• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
1
Question by hayrettinyucel · Nov 14, 2020 at 06:11 PM · iosdpi

Screen.dpi returning wrong value for iPhone 12 devices.

Looks like Screen.dpi is reporting wrong value for iPhone 12 devices. I used latest 2019 LTS version. Anyone else has this issue? When should we expect a fix for this issue?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Gillissie · Nov 17, 2020 at 07:14 AM 0
Share

I found this question because my iPhone 7+ is reporting 264 dpi instead of 401 like it should be. Seems to be an older problem than just iPhone 12.

avatar image hayrettinyucel Gillissie · Nov 23, 2020 at 12:32 AM 0
Share

I dont think it is an older problem. It could be Unity is missing that in their device generation. I remember I had this issue before and that dpi issue got fixed with a newer version of Unity. This is always happening to me when Apple releases a new product different than before. I just checked the 2019.4.15f1 LTS version and seems like still reporting the wrong value. I will check using an empty project and provide an update. Hopefully unity sees this and get that fixed.

avatar image hayrettinyucel Gillissie · Nov 23, 2020 at 06:34 AM 0
Share

Just confirmed using 2019.4.15f1 LTS and getting these values. - Screen Dpi = 326 - Device Generation = iPhoneUnknown Looks like that unity version is still missing those devices. Not fixed.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Gillissie · Nov 25, 2020 at 02:39 AM

Since the built-in values are unreliable, I made my own static class to define them correctly. I'm still using 2018.4.22f1, so it's understandable that some devices aren't defined, but they can easily be added for newer versions of Unity for anyone that wants to know they're getting the correct values.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.iOS;
 
 /*
 Since Unity's built-in Screen.dpi returns inaccurate values for some iOS devices, I made my own enumeration for all devices known to Unity at this point.
 */
 
 public static class iOSDPI
 {
     public static int dpi
     {
         get
         {
             switch (Device.generation)
             {
                 case DeviceGeneration.iPad1Gen:
                 case DeviceGeneration.iPad2Gen:
                     return 132;
                 case DeviceGeneration.iPhone:
                 case DeviceGeneration.iPhone3G:
                 case DeviceGeneration.iPhone3GS:
                     return 163;
                 case DeviceGeneration.iPad3Gen:
                 case DeviceGeneration.iPad4Gen:
                 case DeviceGeneration.iPad5Gen:
                 case DeviceGeneration.iPad6Gen:
                 case DeviceGeneration.iPad7Gen:
                 case DeviceGeneration.iPadAir1:
                 case DeviceGeneration.iPadAir2:
                 case DeviceGeneration.iPadPro10Inch1Gen:
                 case DeviceGeneration.iPadPro10Inch2Gen:
                 case DeviceGeneration.iPadPro11Inch:
                 case DeviceGeneration.iPadPro1Gen:
                 case DeviceGeneration.iPadPro2Gen:
                 case DeviceGeneration.iPadPro3Gen:
                 case DeviceGeneration.iPadUnknown:
                     return 264;
                 case DeviceGeneration.iPhone4:
                 case DeviceGeneration.iPhone4S:
                 case DeviceGeneration.iPhone5:
                 case DeviceGeneration.iPhone5C:
                 case DeviceGeneration.iPhone5S:
                 case DeviceGeneration.iPhone6:
                 case DeviceGeneration.iPhone6Plus:
                 case DeviceGeneration.iPhone6S:
                 case DeviceGeneration.iPhone7:
                 case DeviceGeneration.iPhone8:
                 case DeviceGeneration.iPhoneSE1Gen:
                 case DeviceGeneration.iPhoneXR:
                 case DeviceGeneration.iPadMini1Gen:
                 case DeviceGeneration.iPadMini2Gen:
                 case DeviceGeneration.iPadMini3Gen:
                 case DeviceGeneration.iPadMini4Gen:
                     //case DeviceGeneration.iPadMini5Gen:    // This enum not defined in Unity 2018.4.22f1
                     return 326;
                 case DeviceGeneration.iPhone6SPlus:
                 case DeviceGeneration.iPhone7Plus:
                 case DeviceGeneration.iPhone8Plus:
                     return 401;
                 case DeviceGeneration.iPhoneX:
                 case DeviceGeneration.iPhoneXS:
                 case DeviceGeneration.iPhoneXSMax:
                 case DeviceGeneration.iPhone11:
                 case DeviceGeneration.iPhone11Pro:
                 case DeviceGeneration.iPhone11ProMax:
                     return 458;
                 // These enums not defined in Unity 2018.4.22f1
                 // case DeviceGeneration.iPhone12
                 // return 460;
                 // case DeviceGeneration.iPhone12Mini
                 // return 476;
                 default:
                     return 460;
             }
         }
     }
 }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hayrettinyucel · Nov 26, 2020 at 03:18 AM 0
Share

This is great. Thanks a lot! However, unity returns unknown for Device.generation property. So, even though if you define it here, you will not be able to identify the device. Am I missing anything here?

avatar image Conor_Envision · May 04 at 03:33 AM 0
Share

I have extended your get dpi function a little to get the dpi's of some unknown iPhones and iPads

Link

getdpi.txt (4.2 kB)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

249 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to cancel iOS LocalNotification? 1 Answer

How to turn on Bluetooth from inside Unity? 3 Answers

Unity Ads Stop Playing On Mobile 0 Answers

#if UNITY_IOS - disables everything in Visual Studio 1 Answer

Mesh colliders stop working after exporting to iOS device. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges