How to detect that a provisioning profile is for development or distribution, programmatically

后端 未结 4 2126
庸人自扰
庸人自扰 2020-12-08 14:41

I would like to detect if a given provisioning profile is a development profile or a distribution (adhoc or app store) profile. I need to do this purely programmatically.

4条回答
  •  执念已碎
    2020-12-08 15:12

    I've build a more concise and efficient version of Toom's code:

    I'll maintain code snippets like this in a gist, you might find a more up to date version here: 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:@"get-task-allow"].length > 0;
        }
    });
    return isDevelopment;
    #endif
    }
    

提交回复
热议问题