SwiftKickMobile / SwiftMessages

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

SwiftMessage is not working iOS 13.3 #372

Closed kanak14 closed 4 years ago

kanak14 commented 4 years ago

Hi Dear,

SwiftMessage is working on iOS 12 and below , Simulator. After update my phone in 13.2 then app will be crashed, Please le me explain how to resolved this issue.

Find the snap-short.

Screenshot 2020-01-06 at 12 43 09 PM (2)

wtmoose commented 4 years ago

Dunno. It isn't crashing for anyone else. What is the error?

Try cleaning your derived data.

BrunoDonini commented 4 years ago

Hi,

I had the same problem. I solved it by forcing the execute of the configureDropShadow() method in the main thread.

From this:

func showSuccess(_ message: String?, title: String? = nil) {
  let success = MessageView.viewFromNib(layout: .cardView)
  success.configureTheme(.success)
  success.configureDropShadow() // <- cause of the problem
  success.configureContent(title: title ?? "", body: message ?? "")
  success.button?.isHidden = true
  var successConfig = SwiftMessages.defaultConfig
  successConfig.presentationStyle = .bottom

  DispatchQueue.main.async {
    SwiftMessages.show(config: successConfig, view: success)
  }
}

to:

func showSuccess(_ message: String?, title: String? = nil) {
  DispatchQueue.main.async {
    let success = MessageView.viewFromNib(layout: .cardView)
    success.configureTheme(.success)
    success.configureDropShadow()
    success.configureContent(title: title ?? "", body: message ?? "")
    success.button?.isHidden = true

    var successConfig = SwiftMessages.defaultConfig
    successConfig.presentationStyle = .bottom

    SwiftMessages.show(config: successConfig, view: success)
  }
}
wtmoose commented 4 years ago

@BrunoDonini how's you get off the main queue? You've got to call SwiftMessages on the main queue or use show(viewProvider:)

BrunoDonini commented 4 years ago

In my case, the showSuccess method is called in an async completion block

wtmoose commented 4 years ago

@BrunoDonini OK I didn't read our post carefully. So you're correct – you shouldn't use UIKit APIs on a background queue, so wrapping the whole thing in DispatchQueue.main.async makes sense.

BrunoDonini commented 4 years ago

Maybe the problem of Kanak is that the configureDropShadow method did not crash in iOS 12 if called in a background thread, instead in iOS 13 it crash