HTTP / 2またはiOSでプッシュ通知と戦った方法

みなさん、こんにちは。最近、私のプロジェクトはiOSデバイスでのプッシュ通知の受信を停止しました。「グーグル」プロセスの後、「リンゴ」のプッシュ通知はhttp / 2プロトコルを介して送信される必要があることが判明しました。





HEADERS
  - END_STREAM
  + END_HEADERS
  :method = POST
  :scheme = https
  :path = /3/device/00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0
  host = api.development.push.apple.com
  authorization = bearer eyAia2lkIjogIjhZTDNHM1JSWDciIH0.eyAiaXNzIjogIkM4Nk5WOUpYM0QiLCAiaWF0I
 jogIjE0NTkxNDM1ODA2NTAiIH0.MEYCIQDzqyahmH1rz1s-LFNkylXEa2lZ_aOCX4daxxTZkVEGzwIhALvkClnx5m5eAT6
 Lxw7LZtEQcH6JENhJTMArwLf3sXwi
  apns-id = eabeae54-14a8-11e5-b60b-1697f925ec7b
  apns-expiration = 0
  apns-priority = 10
  apns-topic = <MyAppTopic>
DATA
  + END_STREAM
    { "aps" : { "alert" : "Hello" } }
Listing 8-3 shows a sample request constructed for a certificate that contains multiple topics.


      
      



これはhttp / 2プロトコルを介したリクエストの例です





. ASP.NET Framework IIS. Windows 2012R2. , HTTP/2 . - . . . "". ANDROID .





ASP.NET Core. ASP.NET Core Linux. Linux HTTP/2.





ASP.NET Core .





ASP.NET Core.





 public class dotAPNSService : IDisposable
    {
        public event EventHandler OnTokenExpiredHandler;
        private ApnsJwtOptions options = null;

        public dotAPNSService(string bundle)
        {
            options = new ApnsJwtOptions()
            {
                BundleId = bundle, //      com.org.test
                CertContent = "       ",//https://developer.apple.com/account/resources/authkeys/list
                KeyId = "  ",//https://developer.apple.com/account/resources/authkeys/list
                TeamId = "  "//https://developer.apple.com/account/resources/authkeys/list
            };
        }

        public void SendNotifications(String[] deviceTokens, String title, String body)
        {
            if (deviceTokens == null || deviceTokens.Length <= 0)
            {
                return;
            }

            if (String.IsNullOrEmpty(title))
            {
                return;
            }

            if (String.IsNullOrEmpty(body))
            {
                return;
            }

            // once you've gathered all the information needed and created an options instance, it's time to call
            var apns = ApnsClient.CreateUsingJwt(new HttpClient( ), options);

            // start the process     
            foreach (String deviceToken in deviceTokens)
            {
                var push = new ApplePush(ApplePushType.Alert)
                    .AddAlert(title, body)
                    .AddToken(deviceToken);

                Send(apns, push, deviceToken);
            }
        }
}
      
      



!!! . . .





NET.Core Docker. VPS REG.RU. VPS.





! . . . .













Visual Studio





.





次に、SSH経由でサーバーに接続するだけです。アクセスキーは電子メールで送信されます。





Dockerからプロジェクトを起動するコマンドを入力します





docker run -d -p 80:80/tcp /
      
      



このコマンドの後、プロジェクトはhttp:// server ipaddress /で利用可能になります。





さらに、すべてのプロジェクトで、受信者トークン、ヘッダー、メッセージの配列を使用して、このアドレスにPOSTリクエストを送信するだけです。すべてが非常に速く行き来します。





PSreg.ru設定でドメイン名をバインドできます。





結果

現時点では、すべてのプッシュメッセージは正常に消えます。そのようなバンドルに問題は見つかりませんでした。プッシュ通知は以前よりもはるかに速く消えるようです。私の記事が同様の問題に直面した人々に役立つことを願っています。








All Articles