NSWidgetExtensionContext openURL Swift

后端 未结 4 1644
滥情空心
滥情空心 2021-01-12 15:08

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 wi

相关标签:
4条回答
  • 2021-01-12 15:37

    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?

    0 讨论(0)
  • 2021-01-12 15:50

    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.

    0 讨论(0)
  • 2021-01-12 15:50

    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 .

    0 讨论(0)
  • 2021-01-12 15:51

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

    0 讨论(0)
提交回复
热议问题