Skip to content

Instantly share code, notes, and snippets.

@choefele
Last active August 29, 2015 14:15
Show Gist options
  • Save choefele/d59571cfd2841a385e1c to your computer and use it in GitHub Desktop.
Save choefele/d59571cfd2841a385e1c to your computer and use it in GitHub Desktop.
How to know at run-time whether your code runs inside an iOS extension
NSDictionary *extensionInfo = [NSBundle.mainBundle objectForInfoDictionaryKey:@"NSExtension"];
NSString *extensionPointIdentifier = extensionInfo[@"NSExtensionPointIdentifier"];
if ([extensionPointIdentifier isEqualToString:@"com.apple.watchkit"]) {
NSLog(@"WatchKit extension");
} else if ([extensionPointIdentifier isEqualToString:@"com.apple.widget-extension"]) {
NSLog(@"Widget extension");
} else if (extensionPointIdentifier == nil) {
NSLog(@"iOS app");
} else {
NSLog(@"Unknown extension type");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment