|
6 | 6 |
|
7 | 7 | #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
|
8 | 8 |
|
| 9 | +#import <os/log.h> |
9 | 10 | #include <memory>
|
10 | 11 |
|
11 | 12 | #include "flutter/fml/memory/weak_ptr.h"
|
@@ -1536,26 +1537,46 @@ - (void)onOrientationPreferencesUpdated:(NSNotification*)notification {
|
1536 | 1537 | - (void)performOrientationUpdate:(UIInterfaceOrientationMask)new_preferences {
|
1537 | 1538 | if (new_preferences != _orientationPreferences) {
|
1538 | 1539 | _orientationPreferences = new_preferences;
|
1539 |
| - [UIViewController attemptRotationToDeviceOrientation]; |
1540 | 1540 |
|
1541 | 1541 | UIInterfaceOrientationMask currentInterfaceOrientation =
|
1542 | 1542 | 1 << [[UIApplication sharedApplication] statusBarOrientation];
|
1543 | 1543 | if (!(_orientationPreferences & currentInterfaceOrientation)) {
|
1544 |
| - // Force orientation switch if the current orientation is not allowed |
1545 |
| - if (_orientationPreferences & UIInterfaceOrientationMaskPortrait) { |
1546 |
| - // This is no official API but more like a workaround / hack (using |
1547 |
| - // key-value coding on a read-only property). This might break in |
1548 |
| - // the future, but currently it´s the only way to force an orientation change |
1549 |
| - [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait) forKey:@"orientation"]; |
1550 |
| - } else if (_orientationPreferences & UIInterfaceOrientationMaskPortraitUpsideDown) { |
1551 |
| - [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortraitUpsideDown) |
1552 |
| - forKey:@"orientation"]; |
1553 |
| - } else if (_orientationPreferences & UIInterfaceOrientationMaskLandscapeLeft) { |
1554 |
| - [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeLeft) |
1555 |
| - forKey:@"orientation"]; |
1556 |
| - } else if (_orientationPreferences & UIInterfaceOrientationMaskLandscapeRight) { |
1557 |
| - [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeRight) |
1558 |
| - forKey:@"orientation"]; |
| 1544 | + if (@available(iOS 16.0, *)) { |
| 1545 | + [self setNeedsUpdateOfSupportedInterfaceOrientations]; |
| 1546 | + for (UIScene* scene in UIApplication.sharedApplication.connectedScenes) { |
| 1547 | + if (![scene isKindOfClass:[UIWindowScene class]]) { |
| 1548 | + continue; |
| 1549 | + } |
| 1550 | + UIWindowSceneGeometryPreferencesIOS* preference = |
| 1551 | + [[UIWindowSceneGeometryPreferencesIOS alloc] |
| 1552 | + initWithInterfaceOrientations:_orientationPreferences]; |
| 1553 | + [(UIWindowScene*)scene |
| 1554 | + requestGeometryUpdateWithPreferences:preference |
| 1555 | + errorHandler:^(NSError* error) { |
| 1556 | + os_log_error(OS_LOG_DEFAULT, |
| 1557 | + "Failed to change device orientation: %@", |
| 1558 | + error); |
| 1559 | + }]; |
| 1560 | + } |
| 1561 | + } else { |
| 1562 | + [UIViewController attemptRotationToDeviceOrientation]; |
| 1563 | + // Force orientation switch if the current orientation is not allowed |
| 1564 | + if (_orientationPreferences & UIInterfaceOrientationMaskPortrait) { |
| 1565 | + // This is no official API but more like a workaround / hack (using |
| 1566 | + // key-value coding on a read-only property). This might break in |
| 1567 | + // the future, but currently it´s the only way to force an orientation change |
| 1568 | + [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait) |
| 1569 | + forKey:@"orientation"]; |
| 1570 | + } else if (_orientationPreferences & UIInterfaceOrientationMaskPortraitUpsideDown) { |
| 1571 | + [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortraitUpsideDown) |
| 1572 | + forKey:@"orientation"]; |
| 1573 | + } else if (_orientationPreferences & UIInterfaceOrientationMaskLandscapeLeft) { |
| 1574 | + [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeLeft) |
| 1575 | + forKey:@"orientation"]; |
| 1576 | + } else if (_orientationPreferences & UIInterfaceOrientationMaskLandscapeRight) { |
| 1577 | + [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeRight) |
| 1578 | + forKey:@"orientation"]; |
| 1579 | + } |
1559 | 1580 | }
|
1560 | 1581 | }
|
1561 | 1582 | }
|
|
0 commit comments