0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

iOSアプリのAmazonリンクからAmazonアプリを起動する方法

Last updated at Posted at 2020-06-25

Info.plistにLSApplicationQueriesSchemesというキーでTypeをArrayにし、そこにアイテムを追加し、TypeをStringでvalueをcom.amazon.mobile.shopping.webにします

アソシエイトリンクの場合は、短縮URLhttps://amzn.to/xxxを使うとAmazon モバイルは現在amzn.toでご利用いただけませんというエラーがでるので通常URLを使う。

urlString = "アソシエイトリンクの通常URLからhttps://を除いた文字列"
let urlStringWithSchema = "com.amazon.mobile.shopping.web://" + urlString
            guard let urlWithSchema = URL(string: urlStringWithSchema) else { return }
            if UIApplication.shared.canOpenURL(urlWithSchema){
                UIApplication.shared.open(urlWithSchema, options: [:], completionHandler: nil)
            } else {
                guard let url = URL(string: urlString) else { return }
                UIApplication.shared.open(url, options: [:], completionHandler: nil)
            }

一度アプリの該当画面からAmazonアプリを開く許可をすると、以後は許可を求められずに勝手にAmazonアプリが開く。これは Cunstom URL Schemas

Apple Developer のリファレンス等にあるような、URL Typesに値を追加する云々は、あくまでSafariなどでブラウジングしていて特定のURLを踏んだときに自社アプリを起動させるための設定なので混同しないように。

参考文献

https://stackoverflow.com/questions/27693062/iphone-ios-amazon-scheme-uri-not-working-anymore-amzn-version-4-3-1-deep-li
amzn://content/item?id=<some valid id>という方式は使えなくなったようだ。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?