7

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.

Undo
  • 25,519
  • 37
  • 106
  • 129
JRystedt
  • 215
  • 2
  • 9
  • Have you added "AppName" to URL Types in your app settings? – PGDev Dec 11 '16 at 14:31
  • I have done so as shown in the info.plist screenshot above – JRystedt Dec 12 '16 at 15:26
  • 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?!? – Georg Nov 20 '18 at 10:38

4 Answers4

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?

Kasper Munck
  • 4,173
  • 2
  • 27
  • 50
  • 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? – Georg Nov 20 '18 at 10:42
  • "double-double (double!) checked that the bundle identifier and URL scheme match" (c) – hbk Mar 31 '20 at 13:44
5

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

Eva Hsueh
  • 61
  • 1
  • 5
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.

Mikita Manko
  • 1,133
  • 9
  • 9
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 .

Enrico Cupellini
  • 447
  • 7
  • 14