From 7a75adbee74aad675a50a7b7006b2952c11a73f0 Mon Sep 17 00:00:00 2001 From: bohan-amplitude <96497806+bohan-amplitude@users.noreply.github.com> Date: Wed, 19 Jan 2022 17:40:12 -0800 Subject: [PATCH] fix: show correct device info for ios app runs on M1 mac (#379) * Fix AMP-41556 device info for app runs on M1 mac Mac with M1 CPU can run ios app, the hw.machine will return iPad platform tag. In the getPlatformString method, added a boolean value isiOSAppOnMac, if it's true and target os is not osx, use hw.model instead of hw.machine. --- Sources/Amplitude/AMPDeviceInfo.m | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Sources/Amplitude/AMPDeviceInfo.m b/Sources/Amplitude/AMPDeviceInfo.m index 2f82f8a4..b90499c7 100644 --- a/Sources/Amplitude/AMPDeviceInfo.m +++ b/Sources/Amplitude/AMPDeviceInfo.m @@ -188,10 +188,17 @@ + (NSString *)generateUUID { } + (NSString *)getPlatformString { -#if !TARGET_OS_OSX - const char *sysctl_name = "hw.machine"; -#else const char *sysctl_name = "hw.model"; +#if TARGET_OS_IOS + BOOL isiOSAppOnMac = NO; + if (@available(iOS 14.0, *)) { + isiOSAppOnMac = [NSProcessInfo processInfo].isiOSAppOnMac; + } + if (!isiOSAppOnMac){ + sysctl_name = "hw.machine"; + } +#elif TARGET_OS_TV || TARGET_OS_WATCH + sysctl_name = "hw.machine"; #endif size_t size; sysctlbyname(sysctl_name, NULL, &size, NULL, 0);