概要
apple-app-site-associationを署名したファイルではなく、JSON形式のAPIにする- JLRoutesを使ってWebPageURLをCustomURLと合わせてハンドリングする
apple-app-site-associationを署名したファイルではなく、JSON形式のAPIにする
iOS 9以降の場合、HTTPSでアクセス可能なドメインであれば apple-app-site-association のファイル自体を署名する必要がなくなりました。
*1
サーバの証明書のみを気にすれば、ファイルの署名の期限切れを気にする必要がなくなります。
また、Content-Typeをapplication/jsonで返せれば良いので、JSON形式のAPIとしてapple-app-site-association を提供することができます。
If your app runs in iOS 9 or later and you use HTTPS to serve the apple-app-site-association file, you can create a plain text file that uses the application/json MIME type and you don’t need to sign it.
JLRoutesを使ってWebPageURLをCustomURLと合わせてハンドリングする
AppIndexingを使うとアプリ側にWebPageURLが渡ってきますが、ハンドリングする部分は煩雑になりがちです。
JLRoutesというライブラリを使うと、WebPageURLをCustomURLと合わせてハンドリングすることができます。*2
ユーザー情報を取得するCustomURLがapple://users/:user_id、WebPageURLがhttps://apple.com/users/:user_id だとすると、以下のように同じような処理をまとめて書けます。
// apple://users/:user_id
JLRoutes *router = [JLRoutes routesForScheme:@"apple"];
[router addRoute:@"/shop/:user_id" handler:^BOOL(NSDictionary *parameters) {
// open user view controller
}];
// https://apple.com/users/:user_id
JLRoutes *router = [JLRoutes routesForScheme:@"https"];
[router addRoute:@"/apple.com/users/:user_id" handler:^BOOL(NSDictionary *parameters) {
// open user view controller
}];
まとめ
apple-app-site-associationを署名したファイルではなく、JSON形式のAPIにする- ファイル自体の署名を気にする必要がなくなる
- JLRoutesを使ってWebPageURLをCustomURLと合わせてハンドリングする
- 同じような処理をまとめて書ける
*1:iOS 8でHandOffやShared Web Credentialに対応している場合はダメ
*2:試してないですが、SwiftだとSwiftRouterが使えそうです