Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open url from Today Extension

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)"

like image 314
nelsballs Avatar asked Nov 14 '16 16:11

nelsballs


1 Answers

  • 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)
    
like image 150
rajtharan-g Avatar answered Nov 01 '22 16:11

rajtharan-g