Open url from Today Extension

I am trying to open a deep link from my today's extension widget to my main application with no luck.

    //ExtensionViewController.swift
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

    let url = URL(string: "ACTION_TODAY://")
    self.extensionContext?.open(url!, completionHandler: { (completed) in
    })
}

Info.plist of the main application: (I think it is ACTION_TODAY://not needed, but only ACTION_TODAYgives me the same result) enter image description here

    //AppDelegate.swift
func application(_ application: UIApplication, open url: URL,
                 sourceApplication: String?, annotation: Any) -> Bool {

    let action_today = "ACTION_TODAY://"
    if url.absoluteString.contains(action_today) {
        return true
    }

    return false
}

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

    let action_today = "ACTION_TODAY://"
    if url.absoluteString.contains(action_today) {
        return true
    }
    return false
}

When I select one of the items in the View collection displayed in today's extension, the console gives me __55-[_NCWidgetExtensionContext openURL:completionHandler:]_block_invoke failed: Error Domain=NSOSStatusErrorDomain Code=-50 "(null)"

+4
source share
1 answer
  • In today's view manager, enter the following code where you need to open the main iOS application from the extension.

    let appURL = NSURL(string: "StarterApplication://")
    
    self.extensionContext?.open(appURL! as URL, completionHandler:nil)
    
+4
source

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


All Articles