5

I'm trying to open a deep link from my today extension widget to my main app 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 app : (I guess ACTION_TODAY:// is not needed, but ACTION_TODAY alone gives 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 item of the collectionView displayed in the today extension, the console gives me a __55-[_NCWidgetExtensionContext openURL:completionHandler:]_block_invoke failed: Error Domain=NSOSStatusErrorDomain Code=-50 "(null)"

nelsballs
  • 105
  • 1
  • 7
  • And for some reasons, it was a really bad idea to include an underscore in the URL Scheme... Removing it has fixed the issue. The widget can now correctly open the container app. – nelsballs Nov 19 '16 at 12:10
  • great, and space is also not allowed there.. ;-) – Mehul Sep 21 '17 at 06:43

1 Answers1

4
  • In today view controller, put the following code where you need to open the main iOS app from the extension.

    let appURL = NSURL(string: "StarterApplication://")
    
    self.extensionContext?.open(appURL! as URL, completionHandler:nil)
    
rajtharan-g
  • 432
  • 5
  • 14