Skip to content

Instantly share code, notes, and snippets.

@nickdowell
Last active January 3, 2017 14:13
Show Gist options
  • Save nickdowell/c68a7abe601dfc67ae57760884e6b87a to your computer and use it in GitHub Desktop.
Save nickdowell/c68a7abe601dfc67ae57760884e6b87a to your computer and use it in GitHub Desktop.
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