1

I am making an sort of similar to dividr in the fact that you have falling objects you must dodge and It works perfectly on the iPhone XR but when I run the simulator for the SE and iphone 7 and other I phones my calculations in my code are messed up, Is there anyway to detect exactly what kind of device they're on? or maybe a better way to go about this to make it universal?

I understand that you can do this

if UIDevice.current.userInterfaceIdiom == .phone
if UIDevice.current.userInterfaceIdiom == .pad

but I'm afraid that isn't specific enough for me

lirikb
  • 81
  • 6
  • If you think you need to detect specific devices then you are probably doing something fundamentally wrong. – rmaddy Jan 17 '19 at 16:11
  • Totally agree with rmaddy - you don't want to be trying to detect every possible device and handling it differently, imagine porting that to Android! If you can't use auto-layout and need to perform your own calculations maybe you just need to adjust by the screen size either through UIScreen.main.bounds.size or the bounds.size of the view containing your falling objects? – Mike Atkins-Spelling Jan 17 '19 at 16:20
  • I was doing something fundamentally wrong by making my app specific to the iPhone XR I have since made it more general thank you! – lirikb Jan 17 '19 at 19:41
  • you should change your question so that it is no longer marked as a duplicate – Julian Silvestri Jan 17 '19 at 20:23

1 Answers1

0

I think the best way to achieve what you are trying to do is by using constraints. Instead of detecting what device the user is using, you should set proper constraints so that your app can be loaded and played on ANY device. https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/ProgrammaticallyCreatingConstraints.html Here is a like on basics.

It is best practice to have an app viewable on many devices and the best way to achieve this is to use constraints. Xcode has 'vary for traits', which allows you to change constraints based on screen width and height!https://www.idev101.com/code/User_Interface/sizes.html This link above gives a good example on the various screen widths and heights (does not include ipads)

What is 'Vary for Traits' in Xcode 8?

here is a link on vary for traits I hope this helps

Julian Silvestri
  • 1,970
  • 1
  • 15
  • 33
  • I will take a look, I am new to IOS development as a hobby and I was not aware that this was possible I thought restraints were only for the story board. Thank you for the help I appreciate it. – lirikb Jan 17 '19 at 16:10
  • Not a problem! don't forget to accept an answer or close the question as it is a duplicate, or change your question so that it is not duplicate – Julian Silvestri Jan 17 '19 at 16:11
  • Hi it turns out I was being too specific in my declarations I have since made it more general and now we are good to go thank you! – lirikb Jan 17 '19 at 19:40