HTTP / 2 or How I Fought PUSH Notifications on iOS

Hello everyone. Recently, my projects stopped receiving push notifications on iOS devices. After the "googling" process, it turned out that push notifications for "apples" should now be sent via the http / 2 protocol.





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.


      
      



Here is an example of an http / 2 request





. 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





.





Then it simply connects to our server via SSH. access keys will be sent to you by e-mail.





Enter the command to launch your project from docker





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



after this command your project will be available at http: // server ipaddress /





Further in all projects, I simply send a post request to this address with an array of recipient tokens, header and message. Everything goes and comes just super fast.





PS You can bind a domain name in the reg.ru settings.





Outcome

At the moment, all push messages go off normally. No problems with such a bundle were found. It even seems that push notifications go away much faster than it worked before. I hope my article will help those who faced a similar problem.








All Articles