如何从我的应用程序中打开亚马逊应用程序? [英] How to open Amazon app from within my app?

查看:51
本文介绍了如何从我的应用程序中打开亚马逊应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码从我的应用程序中打开 Amazon 应用程序:

I'm trying to open Amazon app from within my app using following code:

if let url = URL(string: "amzn://"),
    UIApplication.shared.canOpenURL(url) {
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else if let url = URL(string: "https://www.amazon.com") {
    // fallback
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
}

当我将它用于 Youtube 应用程序时,这就像一个魅力.但是,现在使用亚马逊,它只是在报告此错误时默默地失败了:

This worked like a charm when I used it for the Youtube app. However, now with Amazon it just silently fails while it reports this error:

2018-10-11 10:38:09.794370+0200 App[9739:3023026] -canOpenURL:URL 失败:amzn://" - 错误:操作无法完成.(OSStatus 错误 -10814.)"

2018-10-11 10:38:09.794370+0200 App[9739:3023026] -canOpenURL: failed for URL: "amzn://" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"

我在 Info.plist 中向 LSApplicationQueriesSchemes 添加了 url 方案,但这没有任何改变:

I've added url scheme to LSApplicationQueriesSchemes in Info.plist, but this changed nothing:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>amzn</string>
</array>

更奇怪的是,它甚至没有打开回退 URL - 我希望如果 canOpen 失败,第二个分支会工作.

What is even weirder, it does not even open the fallback URL - I would expect that if the canOpen fails, the second branch would work.

推荐答案

所以经过一些更多的研究,基于 https://www.appsight.io 看来亚马逊应用没有使用"amzn://" url scheme,而是"amazonToAlipay://".将其更改为此后,UIApplication.shared 将打开亚马逊应用程序.

So after some more research, based on https://www.appsight.io it seems that the amazon app does not use "amzn://" url scheme, but "amazonToAlipay://". After changing it to this, the UIApplication.shared opens the Amazon app.

感谢@LinusGeffarth 和他对另一个相关问题的回答.

Thanks to @LinusGeffarth and his answer to another related question.

这篇关于如何从我的应用程序中打开亚马逊应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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