Skip to content

Commit fb4d26e

Browse files
MaximeLMp2
authored andcommitted
Add compiler flag to disable UIApplication calls (#280)
Specifying `P2_APP_EXTENSION` ensures the framework can be compiled for an app extension.
1 parent 947522e commit fb4d26e

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Contributors
33

44
Contributors to the codebase, in reverse chronological order:
55

6+
- Maxime Le Moine, @MaximeLM
67
- Seb Skuse, @sebskuse
78
- David Hardiman, @dhardiman
89
- Amaury David, @amaurydavid

Sources/iOS/OAuth2Authorizer+iOS.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,13 @@ open class OAuth2Authorizer: OAuth2AuthorizerUI {
5555
*/
5656
public func openAuthorizeURLInBrowser(_ url: URL) throws {
5757

58-
// By asking for the shared instance method by using the "value for key" method on UIApplication, we are able to
59-
// bypass the Swift compilation restriction that blocks the library from being compiled for an extension when
60-
// directly referencing it. We do it as an optional so in the advent of this method being called, like in an
61-
// extension, we handle it as though its not supported.
62-
guard let application = UIApplication.value(forKey: "sharedApplication") as? UIApplication else {
63-
throw OAuth2Error.unableToOpenAuthorizeURL
64-
}
65-
66-
if !application.openURL(url) {
58+
#if !P2_APP_EXTENSIONS
59+
if !UIApplication.shared.openURL(url) {
6760
throw OAuth2Error.unableToOpenAuthorizeURL
6861
}
62+
#else
63+
throw OAuth2Error.unableToOpenAuthorizeURL
64+
#endif
6965
}
7066

7167
/**

0 commit comments

Comments
 (0)