LoginSignup
37
32

More than 5 years have passed since last update.

APNs Provider APIとAPNs Auth Keyを使ったAPNs送信【毎年のAPNS証明書更新が不要に】

Posted at

はじめに

APNs Provider APIとAPNs Auth Keyを使うと、
旧来のAPNs Push通知とくらべて様々なメリットがあります。

アプリ毎に証明書を用意しなくて良い

HTTPヘッダーに付与するバンドルIDを変えるだけで、
対象のアプリを切り替え可能です。

証明書を更新しなくて良い

いままではAmazon SNSやLogPushなど複数の配信方法を使っていると、
証明書の更新が地味に手間でした。
APNs Auth Keyは有効期限が無いので、毎年の更新もれの心配もしなくて安心です。

HTTP2 + JWT(JSON Web Token)なので実装がシンプル

HTTPヘッダーにJWTトークンを入れて、HTTP2でPOSTするだけなので簡単です。

複数の端末に配信する場合も、HTTP2なので単一のコネクションで複数回POSTするだけです。

デメリット

Amazon SNSがまだ対応してません。(07/1/7現在)

準備

バンドルID, デバイストークンの他に、
Apple Developer Programのサイトから下記のデータを用意します。

  • Term ID
  • APNs Auth Key

Term ID

Membershipページに記載されています。

APNs Auth Key

Certificates, Identifiers & Profiles

左メニューの「Certificates」 - 「APNs Auth Key」

右上の「+(Add)」ボタン

「Apple Push Notification Authentication Key (Sandbox & Production)」
を選択して「Continue」

発行したAPNs Auth Keyの「Key ID」とダウンロードできる「p8ファイル(プライベートキー)」を使います。

ソースコード

nodejsを使った、複数のiPhoneへ送信する実装です。
https://github.com/m-hosoi/node-apns-provider-api

37
32
2

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
37
32