使用NSProcessInfo (NSProcessInfoPlatform) 判断
@interface NSProcessInfo (NSProcessInfoPlatform)
@property (readonly, getter=isMacCatalystApp) BOOL macCatalystApp API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0));
@property (readonly, getter=isiOSAppOnMac) BOOL iOSAppOnMac API_AVAILABLE(macos(11.0), ios(14.0), watchos(7.0), tvos(14.0));
@end
if (@available(iOS 14.0, *)) {
isiOSAppOnMac = [NSProcessInfo processInfo].isiOSAppOnMac;
NSLog(@"%@", isiOSAppOnMac?@"运行在Mac环境" : @"没有运行在Mac环境");
}
网友评论