Search Unity

iOS.DeviceGeneration does not include iPad (2018) for almost a year (Rant)

Discussion in 'iOS and tvOS' started by Neonlyte, Jan 20, 2019.

  1. Neonlyte

    Neonlyte

    Joined:
    Oct 17, 2013
    Posts:
    516
    There was a new entry-level iPad released in 2018. The model identifiers are "iPad7,5" and "iPad7,6". And Unity has not added them in the API since the release. During this period, however, new iPhones and iPad Pros (3rd Gen.) were added.

    This has been bothering me since my game targets 120fps on capable iPad Pros, and my custom sprite player depends on `Application.targetFrameRate` being properly set.

    What happened was:
    1. Due to the way Unity (up till 2018.2) parses the model identifiers in the native code, a wrong enum item was returned when I read `iOS.Device.generation` property. In the native code, there is no proper enum items defined and there were no conditions implemented in C function `ParseDeviceGeneration`. That native code is a case of "reaching the end of a non-void function". In C that is just a warning and, because it's C, `iPadPro10Inch2Gen` got returned.
    2. My frame rate setting code thinks iPad 2018 is a iPad Pro (2nd Gen., 10.5") because of this, and it set `Application.targetFrameRate` to 120.
    3. The frame rate setting was sent to native code, native code get the maximum frame rate on this device, and bounded the value down to 60 and set the `CADisplayLink` property. HOWEVER, the C# API is not aware of this out-of-bound and `targetFrameRate` is still set to 120.
    4. My frame-rate-dependent sprite player reads the `targetFrameRate` and behaves weirdly.
    There are a ton of ways to resolve/workaround this issue. I chose to patch the native code with a hack that treats iPad 2018 as an older model. I have to add this hack back every time I replace the whole Xcode project:
    Code (CSharp):
    1.     else if (!strncmp(model, "iPad7,", 6))
    2.     {
    3.         int rev = atoi(model + 6);
    4.         if (rev == 1 || rev == 2)
    5.             return deviceiPadPro2Gen;
    6.         else if (rev == 3 || rev == 4)
    7.             return deviceiPadPro10Inch2Gen;
    8.         //HACK:
    9.         else if (rev == 5 || rev == 6)
    10.             return deviceiPad5Gen;
    11.     }
    I have read in the release notes that in later Unity releases, device generation parsing has been revamped, so my issue was partially solved. Still, I have still yet to find traces of an `iPad6Gen` or similar in the documentation. It is not in 2018.3, it is not in 2019.1.

    I did submit a bug report (1065983), but I did not reply when I was asked to provide a small project for reproduction because I thought my issue was too small and too obvious. I apologize for my attitude and no-response, and I'll provide a reproduction if my overall case was not straightforward for investigation. And I do hope my long rant could help Unity stay updated with the latest tech news.
     
  2. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    Hey there,

    I just skimmed through your post and I'm suggesting something really obvious, but maybe you missed it: You can get the ModelName not only through Device.generation, but also through SystemInfo.deviceModel. The string didn't fail me so far and I think there is no extra changes on unity's side necessary to support new devices. I can't confirm if that is the case for iPad7,5, but I would give it a try if you haven't already. You can find all device names over here (Identifier column): https://www.theiphonewiki.com/wiki/Models
     
  3. Neonlyte

    Neonlyte

    Joined:
    Oct 17, 2013
    Posts:
    516
    Thanks for the tip regarding alternative API.

    My point is, though, that if they did update enums quickly for iPhone Xs which released later than that iPad, there is no reason for them not to add it. It's more about correct behavior of the API than about the significance of the new device.

    Also for a minor reason, using enums allows source code to ignore the underlying value which reduces chances of using invalid values by accident.
     
  4. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    Yep, totally get your point. If there is an API it should be complete and maintained as expected. Sadly it seems like their iphone enum needs to be maintained manually and is not of too high priority.
    At least if there is a mistake in your strings you can fix it and don't need to wait for Unity to fix it and for something like devices, I'm really not sure if it is a feasible solution to use enums since the enum will always grow with the number of released devices. Anyways, I would recommend switching to SystemInfo.deviceModel instead of needing to hack your XCode project code to do what it is supposed to do, nonetheless your rant is totally valid ;)