NSWidgetExtensionContext openURL Swift
Asked Answered
S

4

8

I have been attempting to implement a button to open my iOS app from its widget. I realize this issue has been beaten to death on the forums but I cannot find explanation with the specific error I am receiving. Perhaps some of you more experienced iOS developers can shed some light on this.

I am developing an update to one of my iOS apps for iOS 10 using XCode 8.1 and Swift 2.

Code for my widget's button: enter image description here

URL scheme added to the widget's info.plist: enter image description here

The runtime error I receive when pressing the OpenApp button:

AppWidget[11872:3577323] __55-[_NCWidgetExtensionContext openURL:completionHandler:]_block_invoke failed: Error Domain=NSOSStatusErrorDomain Code=-10814 "(null)"

// Note: app name has been substituted with appropriate generics.

Slobber answered 5/11, 2016 at 15:49 Comment(3)
Have you added "AppName" to URL Types in your app settings?Falk
I have done so as shown in the info.plist screenshot aboveSlobber
Did you find the solution to your problem? I also have registered my url-scheme and my extension is trying to open my app, but I only see [_NCWidgetExtensionContext openURL:completionHandler:]_block_invoke failed: Error Domain=NSOSStatusErrorDomain Code=-50 "(null)" in the console. Maybe it's the same issue?!?Aili
P
11

I often find the OS Status lookup site pretty useful to infer details from errors. An OS error with code -10814 is a kLSApplicationNotFoundErr, which describes the scenario when:

No application in the Launch Services database matches the input criteria.

It sounds like your application has not been properly registered with the system as a consumer of the URL scheme you are using. Have you double-double (double!) checked that the bundle identifier and URL scheme match? Have you verified that your app can be launched with the URL from Safari?

Philology answered 14/12, 2016 at 10:5 Comment(2)
I am having the kind of same error as the author of this article here. I tribble checked my bundle_identifier und url scheme and everything... still... I am getting an -50 error (didn't find a proper one from the link you posted :( ) Do you have any other ideas for me?Aili
"double-double (double!) checked that the bundle identifier and URL scheme match" (c)Karlee
P
5

URL scheme should added to the main app's info.plist, not the widget's.

Pemberton answered 9/3, 2017 at 13:33 Comment(0)
E
4

To open the Containing App from Todays Extension:

let myAppUrl = URL(string: "main-screen:")!
extensionContext?.open(myAppUrl, completionHandler: { (success) in
    if (!success) {
        print("error: failed to open app from Today Extension")
    }
})

You also need to add the following lines to the application's info.plist (open as a source code):

    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLName</key>
            <string>com.mikitamanko.bubblewrap</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>main-screen</string>
            </array>
        </dict>
    </array>

right after the

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>

Here's the complete guide how to open the app or share Users Defaults with Extension and the containing app.

Elvyn answered 16/2, 2017 at 5:50 Comment(0)
E
0

Also you should check if you are using any not allowed character for your url scheme. Maybe it is not your case but I was using this and it was wrong:

my_AppName

instead this finally worked :)

myAppName

as said here, the scheme must begin with alphanumeric character and it can contain only alphanumeric characters, +, - and .

Epileptic answered 3/8, 2020 at 15:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.