|
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,51 @@ - (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 |
| - |
1541 |
| - UIInterfaceOrientationMask currentInterfaceOrientation = |
1542 |
| - 1 << [[UIApplication sharedApplication] statusBarOrientation]; |
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"]; |
| 1540 | + |
| 1541 | + if (@available(iOS 16.0, *)) { |
| 1542 | + for (UIScene* scene in UIApplication.sharedApplication.connectedScenes) { |
| 1543 | + if (![scene isKindOfClass:[UIWindowScene class]]) { |
| 1544 | + continue; |
| 1545 | + } |
| 1546 | + UIWindowScene* windowScene = (UIWindowScene*)scene; |
| 1547 | + UIInterfaceOrientationMask currentInterfaceOrientation = |
| 1548 | + 1 << windowScene.interfaceOrientation; |
| 1549 | + if (!(_orientationPreferences & currentInterfaceOrientation)) { |
| 1550 | + [self setNeedsUpdateOfSupportedInterfaceOrientations]; |
| 1551 | + UIWindowSceneGeometryPreferencesIOS* preference = |
| 1552 | + [[UIWindowSceneGeometryPreferencesIOS alloc] |
| 1553 | + initWithInterfaceOrientations:_orientationPreferences]; |
| 1554 | + [windowScene |
| 1555 | + requestGeometryUpdateWithPreferences:preference |
| 1556 | + errorHandler:^(NSError* error) { |
| 1557 | + os_log_error(OS_LOG_DEFAULT, |
| 1558 | + "Failed to change device orientation: %@", |
| 1559 | + error); |
| 1560 | + }]; |
| 1561 | + } |
| 1562 | + } |
| 1563 | + } else { |
| 1564 | + UIInterfaceOrientationMask currentInterfaceOrientation = |
| 1565 | + 1 << [[UIApplication sharedApplication] statusBarOrientation]; |
| 1566 | + if (!(_orientationPreferences & currentInterfaceOrientation)) { |
| 1567 | + [UIViewController attemptRotationToDeviceOrientation]; |
| 1568 | + // Force orientation switch if the current orientation is not allowed |
| 1569 | + if (_orientationPreferences & UIInterfaceOrientationMaskPortrait) { |
| 1570 | + // This is no official API but more like a workaround / hack (using |
| 1571 | + // key-value coding on a read-only property). This might break in |
| 1572 | + // the future, but currently it´s the only way to force an orientation change |
| 1573 | + [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait) |
| 1574 | + forKey:@"orientation"]; |
| 1575 | + } else if (_orientationPreferences & UIInterfaceOrientationMaskPortraitUpsideDown) { |
| 1576 | + [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortraitUpsideDown) |
| 1577 | + forKey:@"orientation"]; |
| 1578 | + } else if (_orientationPreferences & UIInterfaceOrientationMaskLandscapeLeft) { |
| 1579 | + [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeLeft) |
| 1580 | + forKey:@"orientation"]; |
| 1581 | + } else if (_orientationPreferences & UIInterfaceOrientationMaskLandscapeRight) { |
| 1582 | + [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeRight) |
| 1583 | + forKey:@"orientation"]; |
| 1584 | + } |
1559 | 1585 | }
|
1560 | 1586 | }
|
1561 | 1587 | }
|
|
0 commit comments