Programmatically detect if iOS app is running on a Mac,
is that possible?
is that possible?
Code Block if (@available(iOS 14.0, *)) { if ([NSProcessInfo processInfo].isiOSAppOnMac) { NSLog(@"I'M ON MAC"); }else{ NSLog(@"IM NOT ON MAC"); } }
Code Block objc - (BOOL)isiOSAppOnMac { if (@available(iOS 14.0, *)) { return NSProcessInfo.processInfo.isiOSAppOnMac; } return false; }
Code Block swift func isiOSAppOnMac() -> Bool { if #available(iOS 14.0, *) { return ProcessInfo.processInfo.isiOSAppOnMac } return false }
There is at least one compatibility issue currently - I found that using UIReferenceLibraryViewController crashes unexpectedly on an iOS app running on a Mac with
*** Assertion failure in void *DictionaryServicesLibrary(void)(), _UIDictionaryManager.m:25
I ended up adding a ProcessInfo check to avoid this.
ProcessInfo.processInfo.isMacCatalystApp
returns true for:
If you specifically wants to know for (2), then use ProcessInfo.processInfo.isiOSAppOnMac
Now you can simply use this:
if ([NSProcessInfo processInfo].isiOSAppOnMac) {
NSLog(@"iOS app is running on MAC");
}