skip to Main Content

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:

Thread 3: EXC_BAD_ACCESS (code=1, address=0x10)

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


  1. Credential Provider extensions are not permitted to open urls.

    From the documentation

    Each extension point determines whether to support this method, or under which conditions to support this method. In iOS, the Today and iMessage app extension points support this method. An iMessage app extension can use this method only to open its parent app, and only if the parent app is shown on the iOS home screen.

    Login or Signup to reply.
  2. I managed to launch the main app from autofill extension using responder chain like:

    guard let url = URL(string: "myapp://") else { return }
    
    let selectorOpenURL = #selector(UIApplication.openURL)
    
    var responder = rootViewController.next
    while let nextResponder = responder {
        if nextResponder.responds(to: selectorOpenURL) {
            nextResponder.perform(selectorOpenURL, with: url)
            break
        }
        responder = nextResponder.next
    }
    

    where rootViewController is the view controller you present for this extension.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search