DeviceSettings.mm 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. #include <sys/types.h>
  2. #include <sys/sysctl.h>
  3. #include "UnityAppController.h"
  4. #include "UnityView.h"
  5. #include "DisplayManager.h"
  6. // ad/vendor ids
  7. #if UNITY_USES_IAD
  8. #include <AdSupport/ASIdentifierManager.h>
  9. #include <AppTrackingTransparency/ATTrackingManager.h>
  10. static id QueryASIdentifierManager()
  11. {
  12. static bool _queryAttempted = false;
  13. static id _manager = nil;
  14. if (_queryAttempted)
  15. return _manager;
  16. _queryAttempted = true;
  17. NSBundle* bundle = [NSBundle bundleWithPath: @"/System/Library/Frameworks/AdSupport.framework"];
  18. if (bundle)
  19. {
  20. [bundle load];
  21. _manager = [NSClassFromString(@"ASIdentifierManager") performSelector: @selector(sharedManager)];
  22. return _manager;
  23. }
  24. return nil;
  25. }
  26. API_AVAILABLE(ios(14))
  27. static bool QueryAttTrackingAuthorization()
  28. {
  29. static bool _status = false;
  30. // if authorization is revoked, app is restarted, so we can cache
  31. if (!_status)
  32. {
  33. static Class _ATTrackingManager = nil;
  34. static bool _classLoadAttempted = false;
  35. if (!_classLoadAttempted)
  36. {
  37. _classLoadAttempted = true;
  38. NSBundle* bundle = [NSBundle bundleWithPath: @"/System/Library/Frameworks/AppTrackingTransparency.framework"];
  39. if (bundle)
  40. {
  41. [bundle load];
  42. _ATTrackingManager = NSClassFromString(@"ATTrackingManager");
  43. }
  44. }
  45. if (_ATTrackingManager)
  46. {
  47. id status = [_ATTrackingManager valueForKey: @"trackingAuthorizationStatus"];
  48. if (status && [status isKindOfClass: NSNumber.class])
  49. {
  50. NSNumber* tackingStatus = status;
  51. _status = ATTrackingManagerAuthorizationStatusAuthorized == tackingStatus.unsignedIntValue;
  52. }
  53. }
  54. }
  55. return _status;
  56. }
  57. #endif
  58. extern "C" const char* UnityAdIdentifier()
  59. {
  60. static const char* _ADID = NULL;
  61. #if UNITY_USES_IAD
  62. static const NSString* _ADIDNSString = nil;
  63. // ad id can be reset during app lifetime
  64. id manager = QueryASIdentifierManager();
  65. if (manager)
  66. {
  67. NSString* adid = [[manager performSelector: @selector(advertisingIdentifier)] UUIDString];
  68. // Do stuff to avoid UTF8String leaks. We still leak if ADID changes, but that shouldn't happen too often.
  69. if (![_ADIDNSString isEqualToString: adid])
  70. {
  71. _ADIDNSString = adid;
  72. free((void*)_ADID);
  73. _ADID = AllocCString(adid);
  74. }
  75. }
  76. #endif
  77. return _ADID;
  78. }
  79. extern "C" int UnityGetLowPowerModeEnabled()
  80. {
  81. return [[NSProcessInfo processInfo] isLowPowerModeEnabled] ? 1 : 0;
  82. }
  83. extern "C" int UnityGetWantsSoftwareDimming()
  84. {
  85. #if !PLATFORM_TVOS && !PLATFORM_VISIONOS
  86. UIScreen* mainScreen = [UIScreen mainScreen];
  87. return mainScreen.wantsSoftwareDimming ? 1 : 0;
  88. #else
  89. return 0;
  90. #endif
  91. }
  92. extern "C" void UnitySetWantsSoftwareDimming(int enabled)
  93. {
  94. #if !PLATFORM_TVOS && !PLATFORM_VISIONOS
  95. UIScreen* mainScreen = [UIScreen mainScreen];
  96. mainScreen.wantsSoftwareDimming = enabled;
  97. #endif
  98. }
  99. extern "C" int UnityGetIosAppOnMac()
  100. {
  101. if (@available(iOS 14, tvOS 14, *))
  102. return [[NSProcessInfo processInfo] isiOSAppOnMac] ? 1 : 0;
  103. return 0;
  104. }
  105. extern "C" int UnityAdTrackingEnabled()
  106. {
  107. bool _AdTrackingEnabled = false;
  108. #if UNITY_USES_IAD
  109. if (@available(iOS 14.0, tvOS 14.0, *))
  110. {
  111. _AdTrackingEnabled = QueryAttTrackingAuthorization();
  112. }
  113. else
  114. {
  115. // ad tracking can be changed during app lifetime
  116. id manager = QueryASIdentifierManager();
  117. if (manager)
  118. _AdTrackingEnabled = [manager performSelector: @selector(isAdvertisingTrackingEnabled)];
  119. }
  120. #endif
  121. return _AdTrackingEnabled ? 1 : 0;
  122. }
  123. extern "C" const char* UnityVendorIdentifier()
  124. {
  125. static const char* _VendorID = NULL;
  126. if (_VendorID == NULL)
  127. _VendorID = AllocCString([[UIDevice currentDevice].identifierForVendor UUIDString]);
  128. return _VendorID;
  129. }
  130. // UIDevice properties
  131. #define QUERY_UIDEVICE_PROPERTY(FUNC, PROP) \
  132. extern "C" const char* FUNC() \
  133. { \
  134. static const char* value = NULL; \
  135. if (value == NULL && [UIDevice instancesRespondToSelector:@selector(PROP)]) \
  136. value = AllocCString([UIDevice currentDevice].PROP); \
  137. return value; \
  138. }
  139. QUERY_UIDEVICE_PROPERTY(UnityDeviceName, name)
  140. QUERY_UIDEVICE_PROPERTY(UnitySystemName, systemName)
  141. QUERY_UIDEVICE_PROPERTY(UnitySystemVersion, systemVersion)
  142. #undef QUERY_UIDEVICE_PROPERTY
  143. // hw info
  144. extern "C" const char* UnityDeviceModel()
  145. {
  146. static const char* _DeviceModel = NULL;
  147. if (_DeviceModel == NULL)
  148. {
  149. size_t size;
  150. ::sysctlbyname("hw.machine", NULL, &size, NULL, 0);
  151. char* model = (char*)::malloc(size + 1);
  152. ::sysctlbyname("hw.machine", model, &size, NULL, 0);
  153. model[size] = 0;
  154. #if TARGET_OS_SIMULATOR
  155. if (!strncmp(model, "arm64", 5) || !strncmp(model, "x86_64", 6))
  156. {
  157. NSString* simModel = [[NSProcessInfo processInfo] environment][@"SIMULATOR_MODEL_IDENTIFIER"];
  158. if ([simModel length] > 0)
  159. {
  160. _DeviceModel = AllocCString(simModel);
  161. ::free(model);
  162. return _DeviceModel;
  163. }
  164. }
  165. #endif
  166. _DeviceModel = AllocCString([NSString stringWithUTF8String: model]);
  167. ::free(model);
  168. }
  169. return _DeviceModel;
  170. }
  171. extern "C" int UnityDeviceCPUCount()
  172. {
  173. static int _DeviceCPUCount = -1;
  174. if (_DeviceCPUCount <= 0)
  175. {
  176. // maybe would be better to use HW_AVAILCPU
  177. int ctlName[] = {CTL_HW, HW_NCPU};
  178. size_t dataLen = sizeof(_DeviceCPUCount);
  179. ::sysctl(ctlName, 2, &_DeviceCPUCount, &dataLen, NULL, 0);
  180. }
  181. return _DeviceCPUCount;
  182. }
  183. extern "C" int UnityGetPhysicalMemory()
  184. {
  185. return (int)(NSProcessInfo.processInfo.physicalMemory / (1024ULL * 1024ULL));
  186. }
  187. // misc
  188. extern "C" const char* UnitySystemLanguage()
  189. {
  190. static const char* _SystemLanguage = NULL;
  191. if (_SystemLanguage == NULL)
  192. {
  193. NSArray* lang = [NSLocale preferredLanguages];
  194. if (lang.count > 0)
  195. _SystemLanguage = AllocCString(lang[0]);
  196. }
  197. return _SystemLanguage;
  198. }
  199. enum DeviceType : uint8_t
  200. {
  201. deviceTypeUnknown = 0,
  202. iPhone = 1,
  203. iPad = 2,
  204. iPod = 3,
  205. AppleTV = 4
  206. };
  207. struct DeviceTableEntry
  208. {
  209. DeviceType deviceType;
  210. uint8_t majorGen;
  211. uint8_t minorGenMin;
  212. uint8_t minorGenMax;
  213. DeviceGeneration device;
  214. };
  215. DeviceTableEntry DeviceTable[] =
  216. {
  217. { iPhone, 2, 1, 1, deviceiPhone3GS },
  218. { iPhone, 3, 1, 3, deviceiPhone4 },
  219. { iPhone, 4, 1, 1, deviceiPhone4S },
  220. { iPhone, 5, 3, 4, deviceiPhone5C },
  221. { iPhone, 5, 1, 2, deviceiPhone5 },
  222. { iPhone, 6, 1, 2, deviceiPhone5S },
  223. { iPhone, 7, 2, 2, deviceiPhone6 },
  224. { iPhone, 7, 1, 1, deviceiPhone6Plus },
  225. { iPhone, 8, 1, 1, deviceiPhone6S },
  226. { iPhone, 8, 2, 2, deviceiPhone6SPlus },
  227. { iPhone, 8, 4, 4, deviceiPhoneSE1Gen },
  228. { iPhone, 9, 1, 1, deviceiPhone7 },
  229. { iPhone, 9, 3, 3, deviceiPhone7 },
  230. { iPhone, 9, 2, 2, deviceiPhone7Plus },
  231. { iPhone, 9, 4, 4, deviceiPhone7Plus },
  232. { iPhone, 10, 1, 1, deviceiPhone8 },
  233. { iPhone, 10, 4, 4, deviceiPhone8 },
  234. { iPhone, 10, 2, 2, deviceiPhone8Plus },
  235. { iPhone, 10, 5, 5, deviceiPhone8Plus },
  236. { iPhone, 10, 3, 3, deviceiPhoneX },
  237. { iPhone, 10, 6, 6, deviceiPhoneX },
  238. { iPhone, 11, 8, 8, deviceiPhoneXR },
  239. { iPhone, 11, 2, 2, deviceiPhoneXS },
  240. { iPhone, 11, 4, 4, deviceiPhoneXSMax },
  241. { iPhone, 11, 6, 6, deviceiPhoneXSMax },
  242. { iPhone, 12, 1, 1, deviceiPhone11 },
  243. { iPhone, 12, 3, 3, deviceiPhone11Pro },
  244. { iPhone, 12, 5, 5, deviceiPhone11ProMax },
  245. { iPhone, 12, 8, 8, deviceiPhoneSE2Gen },
  246. { iPhone, 13, 1, 1, deviceiPhone12Mini },
  247. { iPhone, 13, 2, 2, deviceiPhone12 },
  248. { iPhone, 13, 3, 3, deviceiPhone12Pro },
  249. { iPhone, 13, 4, 4, deviceiPhone12ProMax },
  250. { iPhone, 14, 4, 4, deviceiPhone13Mini },
  251. { iPhone, 14, 5, 5, deviceiPhone13 },
  252. { iPhone, 14, 2, 2, deviceiPhone13Pro },
  253. { iPhone, 14, 3, 3, deviceiPhone13ProMax },
  254. { iPhone, 14, 6, 6, deviceiPhoneSE3Gen },
  255. { iPhone, 14, 7, 7, deviceiPhone14 },
  256. { iPhone, 14, 8, 8, deviceiPhone14Plus },
  257. { iPhone, 15, 2, 2, deviceiPhone14Pro },
  258. { iPhone, 15, 3, 3, deviceiPhone14ProMax },
  259. { iPhone, 15, 4, 4, deviceiPhone15 },
  260. { iPhone, 15, 5, 5, deviceiPhone15Plus },
  261. { iPhone, 16, 1, 1, deviceiPhone15Pro },
  262. { iPhone, 16, 2, 2, deviceiPhone15ProMax },
  263. { iPhone, 17, 3, 3, deviceiPhone16 },
  264. { iPhone, 17, 5, 5, deviceiPhone16e },
  265. { iPhone, 17, 4, 4, deviceiPhone16Plus },
  266. { iPhone, 17, 1, 1, deviceiPhone16Pro },
  267. { iPhone, 17, 2, 2, deviceiPhone16ProMax },
  268. { iPod, 4, 1, 1, deviceiPodTouch4Gen },
  269. { iPod, 5, 1, 1, deviceiPodTouch5Gen },
  270. { iPod, 7, 1, 1, deviceiPodTouch6Gen },
  271. { iPod, 9, 1, 1, deviceiPodTouch7Gen },
  272. { iPad, 2, 5, 7, deviceiPadMini1Gen },
  273. { iPad, 4, 4, 6, deviceiPadMini2Gen },
  274. { iPad, 4, 7, 9, deviceiPadMini3Gen },
  275. { iPad, 5, 1, 2, deviceiPadMini4Gen },
  276. { iPad, 11, 1, 2, deviceiPadMini5Gen },
  277. { iPad, 14, 1, 2, deviceiPadMini6Gen },
  278. { iPad, 2, 1, 4, deviceiPad2Gen },
  279. { iPad, 3, 1, 3, deviceiPad3Gen },
  280. { iPad, 3, 4, 6, deviceiPad4Gen },
  281. { iPad, 6, 11, 12, deviceiPad5Gen },
  282. { iPad, 7, 5, 6, deviceiPad6Gen },
  283. { iPad, 7, 11, 12, deviceiPad7Gen },
  284. { iPad, 12, 1, 2, deviceiPad9Gen },
  285. { iPad, 4, 1, 3, deviceiPadAir1 },
  286. { iPad, 5, 3, 4, deviceiPadAir2 },
  287. { iPad, 11, 3, 4, deviceiPadAir3Gen },
  288. { iPad, 6, 7, 8, deviceiPadPro1Gen },
  289. { iPad, 7, 1, 2, deviceiPadPro2Gen },
  290. { iPad, 6, 3, 4, deviceiPadPro10Inch1Gen },
  291. { iPad, 7, 3, 4, deviceiPadPro10Inch2Gen },
  292. { iPad, 8, 1, 4, deviceiPadPro11Inch },
  293. { iPad, 8, 9, 10, deviceiPadPro11Inch2Gen },
  294. { iPad, 13, 6, 7, deviceiPadPro11Inch3Gen },
  295. { iPad, 8, 5, 8, deviceiPadPro3Gen },
  296. { iPad, 8, 11, 12, deviceiPadPro4Gen },
  297. { iPad, 13, 10, 11, deviceiPadPro5Gen },
  298. { iPad, 11, 6, 7, deviceiPad8Gen },
  299. { iPad, 13, 1, 2, deviceiPadAir4Gen },
  300. { iPad, 13, 16, 17, deviceiPadAir5Gen },
  301. { iPad, 14, 5, 6, deviceiPadPro6Gen },
  302. { iPad, 14, 3, 4, deviceiPadPro11Inch4Gen },
  303. { iPad, 13, 18, 19, deviceiPad10Gen },
  304. { AppleTV, 5, 3, 3, deviceAppleTVHD },
  305. { AppleTV, 6, 2, 2, deviceAppleTV4K },
  306. { AppleTV, 11, 1, 1, deviceAppleTV4K2Gen },
  307. { AppleTV, 14, 1, 1, deviceAppleTV4K3Gen },
  308. };
  309. extern "C" int ParseDeviceGeneration(const char* model)
  310. {
  311. DeviceType deviceType = deviceTypeUnknown;
  312. if (!strncmp(model, "iPhone", 6))
  313. {
  314. deviceType = iPhone;
  315. model += 6;
  316. }
  317. else if (!strncmp(model, "iPad", 4))
  318. {
  319. deviceType = iPad;
  320. model += 4;
  321. }
  322. else if (!strncmp(model, "iPod", 4))
  323. {
  324. deviceType = iPod;
  325. model += 4;
  326. }
  327. else if (!strncmp(model, "AppleTV", 7))
  328. {
  329. deviceType = AppleTV;
  330. model += 7;
  331. }
  332. char* endPtr;
  333. int majorGen = (int)strtol(model, &endPtr, 10);
  334. int minorGen = (int)strtol(endPtr + 1, &endPtr, 10);
  335. if (strlen(endPtr) == 0)
  336. {
  337. for (int i = 0; i < sizeof(DeviceTable) / sizeof(DeviceTable[0]); ++i)
  338. {
  339. if (deviceType != DeviceTable[i].deviceType)
  340. continue;
  341. if (majorGen != DeviceTable[i].majorGen)
  342. continue;
  343. if (minorGen < DeviceTable[i].minorGenMin || minorGen > DeviceTable[i].minorGenMax)
  344. continue;
  345. return DeviceTable[i].device;
  346. }
  347. }
  348. if (deviceType == iPhone)
  349. return deviceiPhoneUnknown;
  350. else if (deviceType == iPad)
  351. return deviceiPadUnknown;
  352. else if (deviceType == iPod)
  353. return deviceiPodTouchUnknown;
  354. return deviceUnknown;
  355. }
  356. extern "C" int UnityDeviceGeneration()
  357. {
  358. static int _DeviceGeneration = deviceUnknown;
  359. if (_DeviceGeneration == deviceUnknown)
  360. {
  361. const char* model = UnityDeviceModel();
  362. _DeviceGeneration = ParseDeviceGeneration(model);
  363. }
  364. return _DeviceGeneration;
  365. }
  366. // Currently a manual process to add devices that have a cutout (notch). If you add one here you need to also update UnityView GetCutoutToScreenRatio()
  367. extern "C" int UnityDeviceHasCutout()
  368. {
  369. switch (UnityDeviceGeneration())
  370. {
  371. case deviceiPhoneX: case deviceiPhoneXS: case deviceiPhoneXSMax: case deviceiPhoneXR:
  372. case deviceiPhone11: case deviceiPhone11Pro: case deviceiPhone11ProMax:
  373. case deviceiPhone12: case deviceiPhone12Mini: case deviceiPhone12Pro: case deviceiPhone12ProMax:
  374. case deviceiPhone13: case deviceiPhone13Mini: case deviceiPhone13Pro: case deviceiPhone13ProMax:
  375. case deviceiPhone14: case deviceiPhone14Plus: case deviceiPhone14Pro: case deviceiPhone14ProMax:
  376. case deviceiPhone15: case deviceiPhone15Plus: case deviceiPhone15Pro: case deviceiPhone15ProMax:
  377. case deviceiPhone16: case deviceiPhone16Plus: case deviceiPhone16Pro: case deviceiPhone16ProMax: case deviceiPhone16e:
  378. return 1;
  379. default:
  380. return 0;
  381. }
  382. }
  383. // Devices with a cutout do not support Portrait UpsideDown orientation.
  384. extern "C" int UnityDeviceSupportsUpsideDown()
  385. {
  386. return UnityDeviceHasCutout() ? 0 : 1;
  387. }
  388. extern "C" int UnityDeviceSupportedOrientations()
  389. {
  390. int orientations = (1 << portrait) | (1 << landscapeLeft) | (1 << landscapeRight);
  391. if (UnityDeviceSupportsUpsideDown())
  392. orientations |= (1 << portraitUpsideDown);
  393. return orientations;
  394. }
  395. extern "C" int UnityDeviceIsForceTouchSupported()
  396. {
  397. return UnityGetUnityView().traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable;
  398. }
  399. extern "C" int UnityDeviceIsStylusTouchSupported()
  400. {
  401. const int deviceGen = UnityDeviceGeneration();
  402. return (deviceGen == deviceiPadPro1Gen ||
  403. deviceGen == deviceiPadPro10Inch1Gen ||
  404. deviceGen == deviceiPadPro2Gen ||
  405. deviceGen == deviceiPadPro10Inch2Gen ||
  406. deviceGen == deviceiPadPro11Inch ||
  407. deviceGen == deviceiPadPro3Gen ||
  408. deviceGen == deviceiPad6Gen) ? 1 : 0;
  409. }
  410. extern "C" int UnityDeviceCanShowWideColor()
  411. {
  412. return UnityGetUnityView().traitCollection.displayGamut == UIDisplayGamutP3;
  413. }
  414. extern "C" float UnityDeviceDPI()
  415. {
  416. static float _DeviceDPI = -1.0f;
  417. if (_DeviceDPI < 0.0f)
  418. {
  419. switch (UnityDeviceGeneration())
  420. {
  421. // iPhone
  422. case deviceiPhone3GS:
  423. _DeviceDPI = 163.0f; break;
  424. case deviceiPhone4:
  425. case deviceiPhone4S:
  426. case deviceiPhone5:
  427. case deviceiPhone5C:
  428. case deviceiPhone5S:
  429. case deviceiPhone6:
  430. case deviceiPhone6S:
  431. case deviceiPhoneSE1Gen:
  432. case deviceiPhone7:
  433. case deviceiPhone8:
  434. case deviceiPhoneXR:
  435. case deviceiPhone11:
  436. case deviceiPhoneSE2Gen:
  437. case deviceiPhoneSE3Gen:
  438. _DeviceDPI = 326.0f; break;
  439. case deviceiPhone6Plus:
  440. case deviceiPhone6SPlus:
  441. case deviceiPhone7Plus:
  442. case deviceiPhone8Plus:
  443. _DeviceDPI = 401.0f; break;
  444. case deviceiPhoneX:
  445. case deviceiPhoneXS:
  446. case deviceiPhoneXSMax:
  447. case deviceiPhone11Pro:
  448. case deviceiPhone11ProMax:
  449. case deviceiPhone12ProMax:
  450. case deviceiPhone13ProMax:
  451. case deviceiPhone14Plus:
  452. _DeviceDPI = 458.0f; break;
  453. case deviceiPhone12:
  454. case deviceiPhone12Pro:
  455. case deviceiPhone13:
  456. case deviceiPhone13Pro:
  457. case deviceiPhone14:
  458. case deviceiPhone14Pro:
  459. case deviceiPhone14ProMax:
  460. case deviceiPhone15:
  461. case deviceiPhone15Plus:
  462. case deviceiPhone15Pro:
  463. case deviceiPhone15ProMax:
  464. case deviceiPhone16:
  465. case deviceiPhone16e:
  466. case deviceiPhone16Plus:
  467. case deviceiPhone16Pro:
  468. case deviceiPhone16ProMax:
  469. _DeviceDPI = 460.0f; break;
  470. case deviceiPhone12Mini:
  471. case deviceiPhone13Mini:
  472. _DeviceDPI = 476.0f; break;
  473. // iPad
  474. case deviceiPad2Gen:
  475. _DeviceDPI = 132.0f; break;
  476. case deviceiPad3Gen:
  477. case deviceiPad4Gen: // iPad retina
  478. case deviceiPadAir1:
  479. case deviceiPadAir2:
  480. case deviceiPadAir3Gen:
  481. case deviceiPadPro1Gen:
  482. case deviceiPadPro10Inch1Gen:
  483. case deviceiPadPro2Gen:
  484. case deviceiPadPro10Inch2Gen:
  485. case deviceiPad5Gen:
  486. case deviceiPad6Gen:
  487. case deviceiPadPro11Inch:
  488. case deviceiPadPro3Gen:
  489. case deviceiPadPro11Inch2Gen:
  490. case deviceiPadPro11Inch3Gen:
  491. case deviceiPadPro4Gen:
  492. case deviceiPadPro5Gen:
  493. case deviceiPad8Gen:
  494. case deviceiPadAir4Gen:
  495. case deviceiPad9Gen:
  496. case deviceiPadAir5Gen:
  497. _DeviceDPI = 264.0f; break;
  498. case deviceiPad7Gen:
  499. _DeviceDPI = 326.0f; break;
  500. // iPad mini
  501. case deviceiPadMini1Gen:
  502. _DeviceDPI = 163.0f; break;
  503. case deviceiPadMini2Gen:
  504. case deviceiPadMini3Gen:
  505. case deviceiPadMini4Gen:
  506. case deviceiPadMini5Gen:
  507. case deviceiPadMini6Gen:
  508. _DeviceDPI = 326.0f; break;
  509. // iPod
  510. case deviceiPodTouch4Gen:
  511. case deviceiPodTouch5Gen:
  512. case deviceiPodTouch6Gen:
  513. case deviceiPodTouch7Gen:
  514. _DeviceDPI = 326.0f; break;
  515. // unknown (new) devices
  516. case deviceiPhoneUnknown:
  517. _DeviceDPI = 326.0f; break;
  518. case deviceiPadUnknown:
  519. case deviceiPadPro6Gen:
  520. case deviceiPadPro11Inch4Gen:
  521. case deviceiPad10Gen:
  522. _DeviceDPI = 264.0f; break;
  523. case deviceiPodTouchUnknown:
  524. _DeviceDPI = 326.0f; break;
  525. }
  526. // If we didn't find DPI, set it to "unknown" value.
  527. if (_DeviceDPI < 0.0f)
  528. _DeviceDPI = 0.0f;
  529. }
  530. return _DeviceDPI;
  531. }
  532. // device id with fallback for pre-ios7
  533. extern "C" const char* UnityDeviceUniqueIdentifier()
  534. {
  535. static const char* _DeviceID = NULL;
  536. if (_DeviceID == NULL)
  537. _DeviceID = UnityVendorIdentifier();
  538. return _DeviceID;
  539. }