29

特定のプロビジョニング プロファイルが開発プロファイルであるか、配布 (アドホックまたはアプリ ストア) プロファイルであるかを検出したいと考えています。これを純粋にプログラムで行う必要があります。

アドホックとアプリストアを検出する方法は既に理解しています。そして、開発と配布に特に興味があります。

各タイプのプロファイルの内部の plists を調べましたが、識別可能な違いは見つかりませんでした (経由security cms -D -i #{@profilePath})。私もopensslAPIを調べて、証明書の操作にこれを使用しています。

これは、カスタムの xcode 自動ビルド システム用です。ビルド前の検証の一環として、指定されたプロファイルが開発用ではないことを確認する必要があります。

これは可能ですか?もしそうなら、どうすればプログラムで2つを区別できますか?

アイデアをお寄せいただきありがとうございます。

4

4 に答える 4

23

Toom のコードのより簡潔で効率的なバージョンを作成しました。

このようなコード スニペットを Gist に維持します。ここで最新バージョンを見つけることができます: https://gist.github.com/steipete/7668246

static BOOL PSPDFIsDevelopmentBuild(void) {
#if TARGET_IPHONE_SIMULATOR
return YES;
#else
static BOOL isDevelopment = NO;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
    // There is no provisioning profile in AppStore Apps.
    NSData *data = [NSData dataWithContentsOfFile:[NSBundle.mainBundle pathForResource:@"embedded" ofType:@"mobileprovision"]];
    if (data) {
        const char *bytes = [data bytes];
        NSMutableString *profile = [[NSMutableString alloc] initWithCapacity:data.length];
        for (NSUInteger i = 0; i < data.length; i++) {
            [profile appendFormat:@"%c", bytes[i]];
        }
        // Look for debug value, if detected we're a development build.
        NSString *cleared = [[profile componentsSeparatedByCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet] componentsJoinedByString:@""];
        isDevelopment = [cleared rangeOfString:@"<key>get-task-allow</key><true/>"].length > 0;
    }
});
return isDevelopment;
#endif
}
于 2013-11-26T23:35:22.633 に答える
10

Bryan Musial のすばらしい回答に基づいて、実行時にアプリケーションから直接「get-task-allow」をチェックできるコードをいくつか書きました。私の場合、このブール値を使用して、デバッグ アプリにのみログインしています。

+ (BOOL)isDevelopmentApp
{
    // Special case of simulator
    if (isSimulator)
    {
        return YES;
    }

    // There is no provisioning profile in AppStore Apps
    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]];
        NSString *profileClearText = [profileWords componentsJoinedByString:@""];

        // Look for debug value
        NSRange debugRange = [profileClearText rangeOfString:@"<key>get-task-allow</key><true/>"];
        if (debugRange.location != NSNotFound)
        {
            return YES;
        }
    }

    // Return NO by default to avoid security leaks
    return NO;
}
于 2013-07-29T17:18:04.207 に答える