简体   繁体   English

来自Today Extension的打开网址

[英]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) 主app的Info.plist :(我猜ACTION_TODAY://不需要,但ACTION_TODAY单独给我相同的结果) 在此输入图像描述

    //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)" 当我选择今天扩展中显示的collectionView项之一时,控制台给我一个__55-[_NCWidgetExtensionContext openURL:completionHandler:]_block_invoke failed: Error Domain=NSOSStatusErrorDomain Code=-50 "(null)"

  • In today view controller, put the following code where you need to open the main iOS app from the extension. 在今天的视图控制器中,将以下代码放在需要从扩展程序打开主iOS应用程序的位置。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Swift在我的应用程序的“今日扩展”中的Safari中打开url - How to open a url in Safari from my Today Extension within my app using Swift 以编程方式从 plist 中获取 URL Scheme,从今天的扩展中 - Programmatically get the URL Scheme from plist, from within a today extension 打开包含今日扩展的应用程序时崩溃 - Crash when open containing app from today extension 从我的应用程序中的“今日扩展”(窗口小部件)打开Safari - Open Safari from my Today Extension (widget) within my app 无法从今天的分机上打开主机应用程序 - Can't open host app from today extension iOs - 如何使用url将数据从Widget(今日扩展)传递到App? - iOs - How to pass data from Widget (Today Extension) to App with url? 当主应用程序未打开时,Swift 如何从今天的扩展中打开特定的视图控制器 - Swift how to open specific viewcontroller from today extension when main app is not open iOS扩展程序中的开放URL方案 - Open URL scheme from iOS extension 使用IntentsUI扩展中的URL打开应用 - Open app with URL from IntentsUI extension 从 Widget 打开宿主应用程序时未调用 AppDelegate 函数(今日扩展) - AppDelegate function not called when open the host application from the Widget (Today Extension)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM