Skip to content

Commit 9322279

Browse files
committed
Add compiler flag CALLBACK_IN_APP_EXTENSIONS for app extension #9
An NSExtensionContext must be set in Manager to open urls
1 parent 4b008c5 commit 9322279

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

Sources/Manager.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,17 @@ open class Manager {
3838
// keep request for callback
3939
var requests: [RequestID: Request] = [:]
4040

41+
#if CALLBACK_IN_APP_EXTENSIONS
42+
// extension context to open url (only if compiled with CALLBACK_IN_APP_EXTENSIONS)
43+
open static var extensionContext: NSExtensionContext?
44+
#endif
45+
4146
// Specify an URL scheme for callback
4247
open var callbackURLScheme: String?
43-
48+
4449
init() {
4550
}
46-
51+
4752
// Add an action handler ie. url path and block
4853
open subscript(action: Action) -> ActionHandler? {
4954
get {
@@ -232,9 +237,13 @@ open class Manager {
232237
return result
233238
}
234239

235-
static func open(url: Foundation.URL) {
240+
public static func open(url: Foundation.URL) {
236241
#if os(iOS) || os(tvOS)
237-
UIApplication.shared.openURL(url)
242+
#if !CALLBACK_IN_APP_EXTENSIONS
243+
UIApplication.shared.openURL(url)
244+
#else
245+
extensionContext?.open(url, completionHandler: nil)
246+
#endif
238247
#elseif os(OSX)
239248
NSWorkspace.shared().open(url)
240249
#endif

0 commit comments

Comments
 (0)