SwiftKickMobile / SwiftMessages

A very flexible message bar for UIKit and SwiftUI.
MIT License
7.24k stars 742 forks source link

Intermittent crash on iOS 13 version 8.0.0 #408

Closed MrJorgeXavier closed 3 years ago

MrJorgeXavier commented 3 years ago

Sometimes when I call the SwiftMessages.show(config:, view:) method the application crashes. It began to happen when I updated the dependency from version 7.0.1 to 8.0.0. I would say that the frequency is pretty high, because its one of our top 3 crashes.

The code that causes the crash:

    static func showMessageStatusBar(message: String) {
        let messageView = MessageView.viewFromNib(layout: .statusLine)
        messageView.backgroundView.backgroundColor = AppData.shared.theme.statusBarMessageBackgroundColor()
        messageView.bodyLabel?.textColor = AppData.shared.theme.statusBarMessageTextColor()
        messageView.configureContent(body: message)

        var statusConfig = SwiftMessages.defaultConfig
        statusConfig.presentationContext = .window(windowLevel: .statusBar)

        SwiftMessages.hideAll()
        SwiftMessages.show(config: statusConfig, view: messageView)
    }

The crash stacktrace:

Screen Shot 2020-08-07 at 11 40 54
wtmoose commented 3 years ago

Did you build the app using the iOS 13 SDK?

wtmoose commented 3 years ago

Never mind. I don't think the code would compile if you did that.

The overrideUserInterfaceStyle property exists in iOS 13 and nobody else has reported this problem. So I suspect there's something unusual about your situation. Any ideas?

MrJorgeXavier commented 3 years ago

Hmm maybe there is really something unusual.

The firebase shows that 79% of the devices where this issue occurs are jailbroken, so I think it can be something on these lines.. The problem is the other 21%, which theorically are not jailbroken devices (which is why I decided to open this issue). Maybe for some reason this 21% are in fact jailbroken but the firebase could not detect.

wtmoose commented 3 years ago

That sounds like a plausible theory. We've had a jailbroken-only issue in the past.

wtmoose commented 3 years ago

I don't like it much, but I can do this if you're still worried about non-jailbroken issues.

if #available(iOS 13.0, *) {
    if self.responds(to: Selector("overrideUserInterfaceStyle")) {
        self.setValue(UIUserInterfaceStyle.light.rawValue, forKey: "overrideUserInterfaceStyle")
    }
}
MrJorgeXavier commented 3 years ago

I understand you, i do not like that solution very much either haha. Since this issue only affects me, I will create a fork of this repo and try this solution and investigate more, so for now you can close this issue without doing anything. When I finish my investigation I will comment here and open a PR of the fork if possible. This way we can avoid this workaround for now, what do you think?

wtmoose commented 3 years ago

Sounds great. Thanks!

anthonyGuiguen commented 3 years ago

I also have this crash on jailbroken devices.