SwiftKickMobile / SwiftMessages

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

Build error on iOS 13 and SWIFTMESSAGES_APP_EXTENSIONS enabled case #378

Closed joohae-kim closed 3 years ago

joohae-kim commented 4 years ago

I got 'shared' is unavailable in application extensions for iOS: Use view controller based solutions where appropriate instead. error on Presenter:install()

guard let containerView = presentationContext.viewValue() else { return }
if let windowViewController = presentationContext.viewControllerValue() as? WindowViewController {
    if #available(iOS 13, *) {
        let scene = UIApplication.shared.keyWindow?.windowScene       // <- HERE!
        windowViewController.install(becomeKey: becomeKeyWindow, scene: scene)
    } else {
        windowViewController.install(becomeKey: becomeKeyWindow)
    }
}
wtmoose commented 4 years ago

Thanks for bringing this up!

wtmoose commented 4 years ago

Sorry for not addressing this in a timely manner. I don't do iMessage extensions, so I had to dig in a little bit. It seems like you're trying to present your message in its own window. I don't think you can do that. You should be using:

config.presentationContext = .viewController(...)

or

config.presentationContext = .view(...)

I wasn't able to reproduce your error though in the iMessageExtensionDemo sample app. Let me know if you still need help with this and I'll see what I can do.