NSWidgetExtensionContext openURL Swift

I am trying to implement a button to open an iOS application from my widget. I understand that this problem was beaten to death on the forums, but I can not find an explanation with the specific error that I get. Perhaps some of you, more experienced iOS developers, may shed some light on this.

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

Code for my widget button: enter image description here

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

Runtime error that I get when I click the OpenApp button:

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

// Note: the application name has been replaced by the corresponding generics.

+5
source share
3 answers

I often find "Searching for OS Status" very useful for outputting details from errors. OS error code -10814 is kLSApplicationNotFoundErr , which describes the scenario when:

None of the applications in the launch database meet the input criteria.

It looks like your application was not properly registered in the system as a consumer of the URL scheme you are using. Do you have a double double (double!) Checkbox that matches the package ID and URL scheme? Have you confirmed that your application can be launched with the URL from Safari?

+5
source

To open the Containing Application from the current schedule:

 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 info.plist application (open as source):

  <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

 <?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 is a complete guide on how to open the application or share default users with the extension and containing the application.

+3
source

The URL scheme should be added to the main info.plist application, and not to the widget.

+2
source

Source: https://habr.com/ru/post/1259330/


All Articles