Skip to content

Do not use UIApplication.shared #23

@dineybomfim

Description

@dineybomfim

'shared' is unavailable in application extensions for iOS and SwiftUI preview targets: Use view controller based solutions where appropriate instead.

There are files in the SDK that need attention, like TamaraSDKCheckoutSwiftUI

Image ``` if url.absoluteString.contains("tamara://") { let application = UIApplication.shared ```

The Lib KingFisher has faced the same issue years ago.
The solution is simple, you can just rely on called UIApplication.shared.
This must be properly safe by macros with proper fallback or u can fallback to use OBJC dynamic messaging and then it will be fine.
(check line 870 of a possible solution:
https://github.com/onevcat/Kingfisher/blob/b450a3b30e0767277a6eed7e02dbdebd7d173da0/Sources/Cache/ImageCache.swift#L205)

Or u go with a direct OBJC workaround like:
extension UIApplication {
static var tamaraShared: UIApplication { (UIApplication.value(forKeyPath: #keyPath(UIApplication.shared)) as? UIApplication ?? .init()) }
}

Then use it instead of shared:
UIApplication.tamaraShared.open(url, options: [:], completionHandler: nil)
etc...

Should be a straight forward fix... otherwise we have to keep changing the local framework files in order to fix it or use the binary framework version.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions