is that possible?
Programmatically detect if iOS app is running on a Mac.
is that possible?
Get a window instance and compare:
window.bounds.size.width VS UIScreen.main.bounds.size.width
These paths are subject to change at a moments notice on iOS Id think. but Debian file directorys probably won't change for a long time. but this is a clever solution. I might consider this a hack, because reasons. like I said, im not sure if they ever change this FS tree.
simulator
/Users/USER/Library/Developer/CoreSimulator/Devices/C065C350-8DC0-4CA5-AF63-A19D998B41DF/data/Containers/Data/Application/5A45A272-AD16-4F1C-939F-BCED22E4A7B4/Documents
Mac apple silicon
/Users/USER/Library/Containers/43B15322-8173-4D40-BE9A-D7539EFC41A7/Data/Documents"
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
How can I test my iOS app to run on Apple silicon. Is it possible from test flight?
Now you can simply use this:
if ([NSProcessInfo processInfo].isiOSAppOnMac) {
NSLog(@"iOS app is running on MAC");
}