Problem: The aim of this post is to find what’s wrong with the code below and find the appropriate solution to open the main app from its Autofill Credential Provider extension target.
Attempt 1: I have a URL scheme set as "open" as shown in the image below:
I then attempt to call this function from my extension viewcontroller:
func openMainApp()
{
let urlStr: String = "open"
let url2 = NSURL(string: urlStr)
self.extensionContext.open(url2! as URL)
}
This crashes before at the open function before opening the main app with the following message:
Thread 2: EXC_BAD_ACCESS (code=1, address=0x10)
I think everything is set up properly to open the app. What am I missing?
Attempt 2: Tried a new configuration to avoid "unwrapping" of url problem and invalid url problems below, changed url scheme to "open:", and set a breakpoint at the "print(url)" line to assure url was formed. Breakpoint vars documented below the code.
Still getting: Thread 3: EXC_BAD_ACCESS (code=1, address=0x10)
func openMainApp()
{
var urlComponents = URLComponents(string: "open:")
if let url = urlComponents?.url {
print(url)
self.extensionContext.open(url)
} else {
print ("NIL URL")
}
}
urlComponents Foundation.URLComponents? some
url Foundation.URL "open:"
_url NSURL "open:" 0x0000000281695540
baseNSObject@0 NSObject
_urlString id 0x100001d80 0x0000000100001d80
_baseURL id 0x800010000010001 0x0800010000010001
_clients NSString "open:" 0x8521474e0e31dd15
_reserved NSURL 0x0000000000000000
Title of the Thread throwing the exception:
ExtensionKit`__62-[EXExtensionContextImplementation openURL:completionHandler:]_block_invoke_2:
2
Answers
Credential Provider extensions are not permitted to open urls.
From the documentation
I managed to launch the main app from autofill extension using responder chain like:
where
rootViewController
is the view controller you present for this extension.