LoginSignup
22
18

More than 3 years have passed since last update.

初めてのユニバーサルリンク(Universal Links)

Posted at

前提

  • 独自ドメインでSSL対応済みのウェブサイトを持っている。

工程

JSONファイルをサーバに配置する

ファイル名は apple-app-site-association とし、拡張子は付けない。
これをドキュメントルートに配置する。

条件としてこのファイルにリダイレクトなしで下記URL構成でアクセス出来なければならない。
https://foo.com/apple-app-site-association

コケ①

とあるパス配下ではダメだった。
https://foo.com/path/to/project に配置するもユニバーサルリンク動作せず。


基本的な中身は以下
{TeamID} はiOS DeveloperCenterから確認できる英数10桁のアレ。
{BundleID} は言わずもがななアレ。

apple-app-site-association
{
  "applinks": {
    "apps": [],
    "details": [
      {
        "appID":"{TeamID}.{BundleID}",
        "paths":[ "*" ]
      }
    ]
  }
}

MIMEタイプを application/json にする

$ curl -v https://foo.com/apple-app-site-association で叩いたときに Content-Type: application/json で返ってこないとイケない。

最終的に .htaccess + ForceType でMIMEを変更

同じドキュメントルートに .htaccess を設置し、以下を記載。

.htaccess
<Files apple-app-site-association>
    ForceType application/json
</Files>

コケ②

httpd.confAddType を使用してみた。
AddType は拡張子指定するものなのでファイル指定は出来ず、cURL結果は変わらなかった。

httpd.conf
:
AddType application/json apple-app-site-association
:

コケ③

.htaccess + DefaultType を使用してみた。
残念ながらcURL結果は変わらなかった:thinking:

.htaccess
<Files apple-app-site-association>
    DefaultType application/json
</Files>

設置した上記ファイルをcURLで叩いてみる。
こうなれば成功。

$ curl -v https://foo.com/apple-app-site-association
:
略
:
< Content-Type: application/json
<
{
  "applinks": {
    "apps": [],
    "details": [
      {
        "appID":"{TeamID}.{BundleID}",
        "paths":[ "*" ]
      }
    ]
  }
}

Capabilities の変更

Xcodeから
Capabilities > Associated Domains をONにし、 applinks:foo.com を追加。

universal_links_attachments_00.png

実機ビルドで動作確認

universal_links_attachments_01.png

SlackにURLを送って、Slackアプリからリンクを踏んでみると、無事アプリが起動。
ユニバーサルリンク童貞卒業。

ちなみに、SafariでURLを直打ちするとアプリは起動せず、ページ上部にAppStoreへのリンクが出てくるようになった。

universal_links_attachments_02.png

22
18
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
22
18