Skip to content

Fix iOS Deployment Target 13 (still working for iOS 12)#774

Merged
ryantrem merged 3 commits into
BabylonJS:masterfrom
EricBeetsOfficial-Opuscope:master
Jun 9, 2021
Merged

Fix iOS Deployment Target 13 (still working for iOS 12)#774
ryantrem merged 3 commits into
BabylonJS:masterfrom
EricBeetsOfficial-Opuscope:master

Conversation

@EricBeetsOfficial-Opuscope

Copy link
Copy Markdown
Contributor

No description provided.

@CedricGuillemet

Copy link
Copy Markdown
Collaborator

LGTM! Thank you

@CedricGuillemet

Copy link
Copy Markdown
Collaborator

@EricBeetsOfficial-Opuscope Is it ok to merge ?

Comment thread Dependencies/xr/Source/ARKit/XR.mm Outdated
#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_13_0)
return [[[[sharedApplication windows] firstObject] windowScene] interfaceOrientation];
#else
return [sharedApplication statusBarOrientation];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep the runtime @available check in the else case since we might still be running on an iOS version >= to 13?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, we required at least the iOS 13 SDK to compile, but at runtime it would work on iOS 13 (using window.windowScene.interfaceOrientation) or iOS <13 (using [[UIApplication sharedApplication] statusBarOrientation]). Is that right?
Is this change trying to make it so you can compile the code against an older SDK that doesn't know anything about sharedApplication.windows.firstObject or window.windowScene.interfaceOrientation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the @available for a conditional compilation because on iOS 13.0, it didn't compile: 'statusBarOrientation' was deprecated in iOS 13.0 error. (I would have liked keep @available which was more elegant :p)

@ryantrem ryantrem Jun 8, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, so basically if you target a high enough iOS version (13 in this case), then some older APIs ([sharedApplication statusBarOrientation] in this case) are no longer available and result in compile errors, correct? If that is the case, then I think we still want to use the newer API if at runtime we see that we are running on a newer OS version, which I think is exactly what @Alex-MSFT is saying above. So something like:

        UIApplication* sharedApplication = [UIApplication sharedApplication];
#if (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_13_0)
        if (!@available(iOS 13.0, *)) {
            return [sharedApplication statusBarOrientation];
        }
#else
        return [[[[sharedApplication windows] firstObject] windowScene] interfaceOrientation];
#endif

So basically only use statusBarOrientation if we are both compiling for a target less than 13, and running on a device that is less than 13.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what Ryan shared makes the most sense, that way we can still always take advantage of the newer interfaceOrientation API when running on iOS 13.0 or later no matter what the min version is.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im afraid that if(!@available(..)) is not allowed. I suggest you this :

  UIApplication* sharedApplication = [UIApplication sharedApplication];
#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_13_0)
   return [[[[sharedApplication windows] firstObject] windowScene] interfaceOrientation];
#else
   if (@available(iOS 13.0, *)) {
       return [[[[sharedApplication windows] firstObject] windowScene] interfaceOrientation];
   }
   else {
       return [sharedApplication statusBarOrientation];
   }
#endif

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I think that is reasonable. I was trying to avoid duplicating that line, but I think my logic was actually wrong anyway. Thanks for making this contribution!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeap, I would also have liked to avoid duplicating these lines :|

@ryantrem ryantrem merged commit f732786 into BabylonJS:master Jun 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants