Last active
January 3, 2017 14:13
-
-
Save nickdowell/c68a7abe601dfc67ae57760884e6b87a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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