LoginSignup
1
0

More than 1 year has passed since last update.

APNsPHP で HTTP/2 プロトコル に対応する

Posted at

ここ最近の案件でiOSのプッシュ通知周りでかなりはまってしまったので(現状解決済み)
その際の解決策を共有します!

APNs【Apple Push Notification service】によるレガシーバイナリプロトコルでのプッシュ通知は、2021 年 3 月 31 日にサポートが終了します。
このため、HTTP/2 ベースの APNs である APNs Provider API に移行する必要があります。

参考 : https://developer.apple.com/jp/news/?id=c88acm2b

ApnsPHP ライブラリを使用している場合

ApnsPHP というプッシュ通知用のライブラリを使用している方は要注意です。
正式版の ApnsPHP は、HTTP/2 プロトコルに対応していません。

でも大丈夫です!
GitHub からプレリリース版の v2.0.0-alpha を持ってきましょう。

Release HTTP/2 Protocol support.
https://github.com/immobiliare/ApnsPHP/releases/tag/v2.0.0-alpha

すでにApnsPHPをインストール済みの方は、以下の3つのファイルを上書きすれば OK です。

ApnsPHP/Abstract.php
ApnsPHP/Message.php
ApnsPHP/Push.php

呼び出し元ソースコードの修正

呼び出し元のソースコードも少し修正する必要があります。

<?php
require_once 'vendor/autoload.php';

$push = new ApnsPHP_Push(
    ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
    'server_certificates_bundle_sandbox.pem',
    ApnsPHP_Abstract::PROTOCOL_HTTP // ★HTTPプロトコルを使用!
);

$push->setRootCertificationAuthority('entrust_root_certification_authority.pem');
$push->connect();
$message = new ApnsPHP_Message('Device Token...');

// Set the topic of the remote notification (the bundle ID for your app)
$message->setTopic('com.armiento.test'); // ★バンドルID

$message->setText('Hello APNs-enabled device!');

$push->add($message);
$push->send();
$push->disconnect();

?>

サーバーもHTTP2に対応させましょう。

必要サーバー要件
openssl 1.0.2e以上
curl 7.46以上(+nghttp2)
PHP 5.5.24以上

1
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
1
0