Is there any way to judge the iPhone is iPhoneX series(iPhone X XR XS XSmax)?
My way is:
#define iPhoneXSeries (([[UIApplication sharedApplication] statusBarFrame].size.height == 44.0f) ? (YES):(NO))
Is there any hidden trouble?
Or is there any better way?
I need to know because iPhoneX series statusbar's height are immutable but other iPhone's statusbar's height can change
So you don't really need to know whether your app is running on an iPhone X-series phone at all — what you're really trying to find out is whether the status bar height can change. And I'll bet that you don't really even care about the status bar so much as you want to know where you can put content in your view so that it will always be unobscured by the status bar and other system objects. Whether that's the case or not, you should make sure that you're asking the right question. Don't rely on the device model to tell you about features, and don't rely on particular features to tell you the device model.
iOS usually gives you a way to find out about the features you need. If your goal is to keep your content visible, you should use UIView
's safeAreaInsets
property and also the safeAreaInsetsDidChange()
method, which the system will call when the safe area changes (e.g. when the status bar height changes). You can then adjust your content to fit the new safe insets. Building your app this way means that you don't have to worry about your app breaking on new device models that have feature sets you don't expect, and you don't have to worry about future iOS updates undermining your assumptions.