iOS通用链接和GET参数 [英] iOS Universal Links and GET parameters

查看:483
本文介绍了iOS通用链接和GET参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试使用Apple Universal Links在iOS上实现应用程序索引(我正在查看 https://developer.apple.com/library/ios/documentation/General/Conceptual/AppSearch/UniversalLinks.html #// apple_ref / doc / uid / TP40016308-CH12-SW2 )。

we're trying to implement app indexing on iOS using the Apple Universal Links (I'm looking at https://developer.apple.com/library/ios/documentation/General/Conceptual/AppSearch/UniversalLinks.html#//apple_ref/doc/uid/TP40016308-CH12-SW2).

在创建和上传关联文件部分中,我看到我可以将索引限制为特定页面,这很好。

In the "Creating and Uploading the Association File" section I see I can limit the indexing to specific pages, which is good.

我想将索引限制为 https://www.mywebsite.com?parameter=something ,我该怎么办?

I'd like to limit the indexing to https://www.mywebsite.com?parameter=something, how can I?

我在想什么关于类似的事情:

I was thinking about something like that:

{
  "applinks": {
    "apps": [],
    "details": [
      {
        "appID": "MYID",
        "paths":[ "*?parameter=*" ]
      }
    ]
  }
}

你认为它可以吗?工作?我无法测试它,因为获取授权在网站根目录上上传文件需要时间,这就是为什么我问你是否认为它可以工作,我想上传文件一次,如果我可以。

Do you think it could work? I can't test it yet because it takes time to get the authorization for uploading files on the website root directory, that's why I'm asking you if you think it could work, I'd like to upload the file just once if I can.

谢谢

推荐答案

,当前#(内联链接)和?(查询参数)不受通用链接支持。 Apple没有提供任何格式来支持 Inline-Links & Query-Parmeter apple-app-site-association 文件中。

NO, Currently #(inline-links) and ?(query-parmeter) not supported by Universal Links. Apple not provided any format to support Inline-Links & Query-Parmeter in apple-app-site-association file.

为了对 https://www.mywebsite.com?parameter=something <进行索引编制/ a>,我正在使用以下json文件。

In order to do indexing to https://www.mywebsite.com?parameter=something, I'm using the following json file.

{
  "applinks": {
    "apps": [],
    "details": [
      {
        "appID": "TEAMID.BUNDLEID",
        "paths":[ "*" ]
      }
    ]
  }
}

如果你想要仅将索引限制为某些参数,例如 query_parmeter1 query_parmeter2 然后您需要在UIApplicationDelegate方法中处理此问题 [UIApplicationDelegate应用程序:continueUserActivity:restorationHandler:] 类似这样的事情

If you want to limit the indexing only to some parameter for example query_parmeter1 and query_parmeter2 then you need to handle this in UIApplicationDelegate method [UIApplicationDelegate application: continueUserActivity: restorationHandler:] something like this

Objective-C:

-(BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler{
    if ([userActivity.activityType isEqualToString: NSUserActivityTypeBrowsingWeb]) {
        NSURL *url = userActivity.webpageURL;
        if ([url.query containsString:@"query_parmeter1"]) {
           //handle code for query_parmeter1
        }else if ([url.query containsString:@"query_parmeter2"]){
           //handle code for query_parmeter2
        }

        return YES;
    }
    return NO;
} 

Swift:

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
    if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
        let url = userActivity.webpageURL!
        let query = url.query ?? ""

        if query.contains("query_parmeter1") {
            // handle code for query_parmeter1
        } else if query.contains("query_parmeter2") {
            // handle code for query_parmeter2
        }

        return true
    }

    return false
}

注意:当点击指向该网站的链接时,此技巧不会阻止该应用程序打开。

Note : This trick won't prevent the app from opening when a link to the website is clicked.

参考文献 - 处理通用链接中的查询参数

这篇关于iOS通用链接和GET参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆