Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this possible to support iPhone X and iOS 8 in same project?

Tags:

xcode

iphone-x

It seems that a "Safe area layout guide before ios 9". error will occur if I trigger the Use Safe Area Layout Guides in the least XCode, does it means supporting both devices is not possible? Any advice? Thanks.

like image 374
DNB5brims Avatar asked Oct 07 '17 03:10

DNB5brims


People also ask

Can I update my iPhone 8 plus to iOS 15?

The iOS 15 will be compatible with iPhone SE (1st generation), iPhone SE (2nd generation), iPhone 6s, iPhone 6s Plus, iPhone 7, iPhone 7 Plus, iPhone 8, iPhone 8 Plus, iPhone XR, iPhone X, iPhone Xs, iPhone Xs Max, iPhone 11 Pro, iPhone 11 Pro Max, iPhone 11, iPhone 12, iPhone 12 mini, iPhone 12 Pro, iPhone 12 Pro Max, ...

What is the latest version of iOS?

Get the latest software updates from Apple The latest version of iOS and iPadOS is 15.6.1. Learn how to update the software on your iPhone, iPad, or iPod touch. The latest version of macOS is 12.5.1. Learn how to update the software on your Mac and how to allow important background updates.


1 Answers

It is totally possible to support iPhone X with a minimum target of iOS 8. (In fact, that's what we currently have in the Khan Academy app.)

What we do is apply the safeAreaInsets in our Swift code using the #available function, like so:

public override func safeAreaInsetsDidChange() {
    if #available(iOS 11.0, *) {
        super.safeAreaInsetsDidChange()
        self.contentCatalogHeaderView?.safeAreaInsetsTopOverride = safeAreaInsets.top
        self.collectionViewLayout.safeAreaInsetsTop = safeAreaInsets.top
    }
}

From your question, it sounds like you're debating whether to use the checkbox in a Storyboard to enable safe area insets. I'm not sure whether it's possible for a Storyboard to support iOS 8 if safe area insets are enabled (I suspect it's not possible). However, you can always store a reference to a layout constraint, and update its constant in your code using the above #available function.

(In Objective-C, the code looks nearly identical, just format it like this:

- (void)viewSafeAreaInsetsDidChange {
    if (@available(iOS 11.0, *)) {
        [super viewSafeAreaInsetsDidChange];
        [self.view setNeedsLayout];
    }
}
like image 131
bryanjclark Avatar answered Oct 11 '22 17:10

bryanjclark