bytedance / Bytedance-UnionAD

MIT License
172 stars 53 forks source link

[BUG] preferredInterfaceOrientationForPresentation crash #105

Closed jeffasd closed 3 years ago

jeffasd commented 4 years ago

BUAdSDKManager version 0 BUAdSDKManager sdkVersion "3.2.6.2"

iOS 13.x iPhone6

Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation 'portrait' must match a supported interface orientation: 'landscapeLeft, landscapeRight'!' First throw call stack: (0x19d858114 0x1b107ecb4 0x19d75b2cc 0x19f9f3988 0x19f8d7050 0x19f8ccd90 0x19f9ef1a4 0x19f9ee5b8 0x19f9ede44 0x19f9ed8b0 0x19f9ed278 0x19f9efc88 0x10109c98c 0x10109c86c 0x1a009dd54 0x19fa36ac0 0x19fa36e04 0x19fa3573c 0x1010fb314 0x19fc1b9a0 0x19d7d6ecc 0x19d7d15b0 0x19d7d1af8 0x19d7d1200 0x1b38cc598 0x1a0097004 0x1a009c5d8 0x100731c6c 0x19d4b0598)

举例 LandscapeViewController继承自UIViewController let baseVC = LandscapeViewController() let presentingVC = UIPresentingViewController() baseVC.present(presentingVC , animated: true, completion: nil) presentingVC.dismiss(animated: true, completion: nil) presentingVC dismisss时 不会调用baseVC的 supportedInterfaceOrientations和preferredInterfaceOrientationForPresentation 方法 但是当在baseVC上点击广告present一个BUWebViewController实例时,BUWebViewController实例dimiss时会调用baseVC的 supportedInterfaceOrientations和preferredInterfaceOrientationForPresentation 方法 如果baseVC的supportedInterfaceOrientations和preferredInterfaceOrientationForPresentation方法返回值配置不一致就导致crash. 希望改进BUWebViewController类,dimiss时不要调用baseVC的supportedInterfaceOrientations和preferredInterfaceOrientationForPresentation方法.

Eason-yangyang commented 4 years ago

首先我们做一个实验

BaseVC 仅支持portrait swift test1VC 仅支持landscapeLeft swift test2VC 仅支持portrait swift test3VC 仅支持portrait Objective-C

BaseVC present test1VC

-test1VC    preferredInterfaceOrientationForPresentation
-test1VC    supportedInterfaceOrientations(多次)

test1VC present test2VC

-test1VC    supportedInterfaceOrientations
-test2VC    supportedInterfaceOrientations
-test2VC    preferredInterfaceOrientationForPresentation
-test2VC    supportedInterfaceOrientations
-test1VC    supportedInterfaceOrientations
-test2VC    supportedInterfaceOrientations(多次)

test2VC present test3VC

-test2VC    supportedInterfaceOrientations
-test3VC    preferredInterfaceOrientationForPresentation
-test3VC    supportedInterfaceOrientations
-test3VC    supportedInterfaceOrientations

test3VC dismiss

-test2VC    preferredInterfaceOrientationForPresentation
-test2VC    supportedInterfaceOrientations
-test3VC    supportedInterfaceOrientations

从上面看,似乎present与dismiss仅与相邻展示页面相关,但是我们改一下test3VC的支持方向,使其与test2VC变得不同,变为仅支持landscapeLeft

BaseVC present test1VC

-test1VC    preferredInterfaceOrientationForPresentation
-test1VC    supportedInterfaceOrientations(多次)

test1VC present test2VC

-test1VC    supportedInterfaceOrientations
-test2VC    supportedInterfaceOrientations
-test2VC    preferredInterfaceOrientationForPresentation
-test2VC    supportedInterfaceOrientations
-test1VC    supportedInterfaceOrientations
-test2VC    supportedInterfaceOrientations(多次)

test2VC present test3VC

-test2VC    supportedInterfaceOrientations
-test3VC    preferredInterfaceOrientationForPresentation
-test3VC    supportedInterfaceOrientations
-test1VC    supportedInterfaceOrientations
-test2VC    supportedInterfaceOrientations
-test3VC    supportedInterfaceOrientations(多次)

test3VC dismiss

-test2VC    supportedInterfaceOrientations
-test3VC    supportedInterfaceOrientations
-test1VC    supportedInterfaceOrientations
-test2VC    supportedInterfaceOrientations
-test3VC    supportedInterfaceOrientations
-test2VC    supportedInterfaceOrientations(多次)

可以看出,存在跨级访问supportedInterfaceOrientations的情况 其原因是方向不同导致触发了系统的 -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] -[UIViewController _updateLastKnownInterfaceOrientationOnPresentionStack:] 等方法

并且,VC supportedInterfaceOrientations不支持preferredInterfaceOrientationForPresentation的时候必定会crash,用户应当遵守这一点。