2013-09-23 15 views
5

私は定期的にアドホックな配布方法でテスターに​​渡すアプリを持っています。これらのテスト担当者の中には、「ボールの上に」あり、プロビジョニングのプロファイルと四半期の有効期限について十分知っていて、テストするための新しいバージョンを再構築するためのナッジを与えることができます。実行時にプロビジョニングプロファイルの有効期限を取得しますか?

しかし、ユーザーの中には、実行を中止してから嫌になるものがあります。おそらくiOSレベルのリマインダを却下しているにもかかわらず、

私は実行時に有効期限をプログラムで取得し、新しいバージョンをプルダウンするよう通知する自分のアプリ内アラートやシステム通知を行うことはできますか?

答えて

6

あなたは

"<key>ExpirationDate</key><date>2014-12-06T00:26:10Z</date>" in [[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"] 

ような何かを探してでも取得していることは容易でありません!このコードは改善することができ、その一部は他のスタックオーバーフローポストに基づいていました。注:別のオプションは、項目plist と/ plistの間のすべてをplist(辞書)にロードすることです。しかし、すでにそこにいるので、手で兄弟を見つけるだけです。

- (NSString*) getExpiry{ 

    NSString *profilePath = [[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"]; 
    // Check provisioning profile existence 
    if (profilePath) 
    { 
     // Get hex representation 
     NSData *profileData = [NSData dataWithContentsOfFile:profilePath]; 
     NSString *profileString = [NSString stringWithFormat:@"%@", profileData]; 

     // Remove brackets at beginning and end 
     profileString = [profileString stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:@""]; 
     profileString = [profileString stringByReplacingCharactersInRange:NSMakeRange(profileString.length - 1, 1) withString:@""]; 

     // Remove spaces 
     profileString = [profileString stringByReplacingOccurrencesOfString:@" " withString:@""]; 


     // Convert hex values to readable characters 
     NSMutableString *profileText = [NSMutableString new]; 
     for (int i = 0; i < profileString.length; i += 2) 
     { 
      NSString *hexChar = [profileString substringWithRange:NSMakeRange(i, 2)]; 
      int value = 0; 
      sscanf([hexChar cStringUsingEncoding:NSASCIIStringEncoding], "%x", &value); 
      [profileText appendFormat:@"%c", (char)value]; 
     } 

     // Remove whitespaces and new lines characters 
     NSArray *profileWords = [profileText componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 

     //There must be a better word to search through this as a structure! Need 'date' sibling to <key>ExpirationDate</key>, or use regex 
     BOOL sibling = false; 
     for (NSString* word in profileWords){ 
      if ([word isEqualToString:@"<key>ExpirationDate</key>"]){ 
       NSLog(@"Got to the key, now need the date!"); 
       sibling = true; 
      } 
      if (sibling && ([word rangeOfString:@"<date>"].location != NSNotFound)) { 
       NSLog(@"Found it, you win!"); 
       NSLog(@"Expires: %@",word); 
       return word; 
      } 
     } 

    } 

    return @""; 
} 
+0

最初の行自体にprofilePathの戻り値がありません。私はxcode 8.2.1を使用しており、このobjective-cコードをswiftで使用しています。 – Skywalker

+0

シミュレータでコードを実行していますか?署名されていないため、シミュレータ上で実行されたときに埋め込み.mobileprovisionファイルはありません。物理デバイス上でコードを実行してみてください(コードは署名されていなければならず、embedded.mobileprovisionファイルは理論上そこにあるべきです)。 – wottle

関連する問題