Skip to content

Instantly share code, notes, and snippets.

@iShawnWang
Last active October 14, 2016 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iShawnWang/d904934efded271d83b36288562df410 to your computer and use it in GitHub Desktop.
Save iShawnWang/d904934efded271d83b36288562df410 to your computer and use it in GitHub Desktop.
Detect Ad Hoc Build Configuration in code at runtime
//AdHoc detect with following 2 conditions :
//1.`embedded.mobileprovision` contains field `ProvisionedDevices` (Debug and Ad Hoc Build contains this field ,Release not)
//2.it is not DEBUG Build , we can use `#ifdef DEBUG` to decide it
NS_INLINE BOOL isAdHoc(){
BOOL isAdHoc = NO;
BOOL isDebug;
#ifdef DEBUG
isDebug=YES;
#else
isDebug=NO;
#endif
NSData *data=[NSData dataWithContentsOfURL:[[NSBundle mainBundle]URLForResource:@"embedded" withExtension:@"mobileprovision"]];
NSString *str=[[NSString alloc]initWithData:data encoding:NSISOLatin1StringEncoding];
NSRange rangeOfDevicesUDIDs = [str rangeOfString:@"ProvisionedDevices"];
isAdHoc = rangeOfDevicesUDIDs.location!=NSNotFound && !isDebug;
return isAdHoc;
}
//Ref
//http://stackoverflow.com/questions/23161261/detecting-if-app-is-ad-hoc?rq=1
//http://stackoverflow.com/questions/3426467/how-to-determine-at-run-time-if-app-is-for-development-app-store-or-ad-hoc-dist
//https://gist.github.com/steipete/7668246
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment