Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
NSString *getApsEnvironment()
{
NSString *provisioningPath = [[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"];
if (!provisioningPath)
return (NSString *)nil;
// NSISOLatin1 keeps the binary wrapper from being parsed as unicode and dropped as invalid
NSScanner *scanner = [NSScanner scannerWithString:[NSString stringWithContentsOfFile:provisioningPath encoding:NSISOLatin1StringEncoding error:NULL]];
if (![scanner scanUpToString:@"<plist" intoString:nil])
return (NSString *)nil;
NSString *plistString;
if (![scanner scanUpToString:@"</plist>" intoString:&plistString])
return (NSString *)nil;
plistString = [plistString stringByAppendingString:@"</plist>"];
NSDictionary *dict = [NSPropertyListSerialization propertyListWithData:[plistString dataUsingEncoding:NSISOLatin1StringEncoding] options:NSPropertyListImmutable format:NULL error:NULL];
if (!dict)
return (NSString *)nil;
NSDictionary *entitlements = dict[@"Entitlements"];
NSString *environment = entitlements[@"aps-environment"];
return environment;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment