How to detect if an iOS app is running on an M1 mac?

Apple's framework allows you to detect if the app is running as an iOS app on Mac by using the process info flag isiOSAppOnMac.

This flag is available from iOS 14.0 and therefore needs to be encapsulated to only run on those versions. Note that since version 14.0 is also the first version for iOS on Mac, you can safely assume that it cannot be on a Mac if the version is prior 14.0.

// Swift
var isiOSAppOnMac = false
if #available(iOS 14.0, *) {
    isiOSAppOnMac = ProcessInfo.processInfo.isiOSAppOnMac
}
print("\(isiOSAppOnMac ? "iOS app on Mac" : "not iOS on Mac")!")

Or if you prefer Objective-C:

// Objective-C
BOOL isiOSAppOnMac = false;
if (@available(iOS 14.0, *)) {
    isiOSAppOnMac = [NSProcessInfo processInfo].isiOSAppOnMac;
}
NSLog(@"%@", isiOSAppOnMac ? @"iOS app on Mac" : @"not iOS app on Mac");

Reference: Apple: Running Your iOS Apps on macOS


This code also checks if the app is running as a Mac Catalyst app.

var isiOSAppOnMac: Bool = {
#if targetEnvironment(macCatalyst)
    return true
#else
    if #available(iOS 14.0, *) {
        return ProcessInfo.processInfo.isiOSAppOnMac
    } else {
        return false
    }
#endif
}()