In iOS or OS X Framework, which contains common code for both its applications and applications, is there a way to determine if the code is running under the main application or one of its extensions? In particular, I would like to determine if the infrastructure is used as part of the WatchKit extension, and not as part of the iPhone application.
UIDevice.currentDevicealways returns iPhone, as that is what works with code. I believe that I can check if it exists WKInterfaceDevice, but it does not seem too elegant.
UIDevice.currentDevice
WKInterfaceDevice
- . , , :
+ (BOOL) isAppExtension { return [[[NSBundle mainBundle] executablePath] containsString:@".appex/"]; }
. , , , .
, , , , WatchKit , .
, WatchKit :
[[[NSBundle mainBundle] bundleIdentifier] hasSuffix:@"watchkitextension"];
Swift:
NSBundle.mainBundle().bundleIdentifier?.hasSuffix("watchkitextension")
, WatchKit , watchkitextension.