openapp.jdmobile://virtual?params={"category":"jump","des":"m","url":"https://u.jd.com/nQo1Y5A","union_open":"union_cps"}
时间: 2023-09-19 19:08:02 浏览: 483
这个链接"openapp.jdmobile://virtual?params={"category":"jump","des":"m","url":"https://u.jd.com/nQo1Y5A","union_open":"union_cps"}"是用来在京东APP中打开指定商品的。
具体使用的代码如下:
```swift
static func goJD(_ url : String){
KeplerApiManager.sharedKPService()?.openKeplerPage(withURL: url, userInfo: nil, successCallback: {
debugPrint("open jd app success")
}, failedCallback: { code, msg in
debugPrint("open jd error code: ", code)
otherGoJD(url)
})
}
static func otherGoJD(_ url : String) {
let jdDict = ["category":"jump", "des":"getCoupon", "url":url ]
guard let jdStr = jdDict.formatJSON() else { return }
let urlStr = "openapp.jdmobile://virtual?params=\(jdStr)"
let utf8Str = urlStr.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
var openSuccess = false
if let jumpURL = URL(string: utf8Str ?? "") {
let isCanOpen = UIApplication.shared.canOpenURL(jumpURL)
if isCanOpen {
UIApplication.shared.open(jumpURL, options: [:], completionHandler: nil)
openSuccess = true
}
}
if (openSuccess == false) {
UIApplication.shared.open(URL(string: url)!, options: [:], completionHandler: nil)
}
}
```
通过调用goJD方法,传入京东商品的URL,即可在京东APP中打开该商品页面。如果无法打开京东APP,则会在浏览器中打开该商品链接。
对于京东的URL Scheme,可以在网上搜索到具体的参数传递方式。
阅读全文