简体   繁体   English

通用链接:如何以编程方式返回上一步?

[英]Universal links: how to go back programmatically?

I have a first iOS native app (let's say the "caller app") that opens a second one (let's say "callee app") with an URL of the form https://calleeapp.com (Universal Link). 我有第一个iOS本机应用程序(假设为“呼叫者应用程序”),该应用程序打开了第二个应用程序(例如为“ callee应用程序”),其URL格式为https://calleeapp.com (通用链接)。 I want the user to perform some task in the "callee app", and when finished then I want to go back automatically to the "caller app" providing the result of such task (URL would be then something similar to https://callerapp.com/check?result=xxxx ). 我希望用户在“ callee app”中执行某些任务,完成后,我想自动返回到“ caller app”,提供该任务的结果(URL将类似于https://callerapp.com/check?result=xxxx )。

What should be the best/appropriate way to handle this? 处理此问题的最佳/适当方法应该是什么?

We'll, you'd need to be able to have code on both the callee and caller app then to do this. 我们将需要您同时在被呼叫者和呼叫者应用程序上都具有代码,然后才能执行此操作。 (Unless a third party app implements some sort of API for callback URLS). (除非第三方应用为回调URL实现了某种API)。

On the caller app though you'd want to look at the following AppDelegate method: 但是,在调用者应用程序上,您需要查看以下AppDelegate方法:

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
    // if it opened the app from some link
    if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
        // the query will give you "result=xxxx"
        if let query = userActivity.webpageURL?.query {
             // code that pulls out the result from the string you get back
        }
     ...

You also have to actually support the universal link by making sure that your AppName.entitlements has the an Associated Domains key with one of the values being applinks:callerapp.com so that the caller app knows it can open urls in that scheme. 您还必须通过确保您的AppName.entitlements具有“关联域”键(其中一个值为applinks:callerapp.com来真正支持通用链接,以便调用方应用知道它可以在该方案中打开网址。 (And vice versa on the callee app if you're also implementing that) (反之亦然,如果您也正在实现被调用者应用,则相反)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM