Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom http headers (for apns-priority and iOS 13) #74

Open
jscalo opened this issue Sep 30, 2019 · 4 comments
Open

Support custom http headers (for apns-priority and iOS 13) #74

jscalo opened this issue Sep 30, 2019 · 4 comments

Comments

@jscalo
Copy link

jscalo commented Sep 30, 2019

iOS 13 requires the apns-priority header to be set to 5 when sending background (content-available = 1) notifications. If the header is left off, it defaults to 10 and the push fails. So currently whenever you send a background notification with Pusher in iOS 13, it fails.

Rather than having the app set this header automatically, I'd prefer to be able to add headers manually so that we can test with other APNS header types.

@ricardopereira
Copy link

ricardopereira commented Oct 25, 2019

This project is not doing a POST request like the Apple examples are doing, it's using a Realtime socket based approach instead (from what I understand from the code). So, there are no HTTP headers. For example, the priority is being set in the data buffer:

- (NSData *)dataWithType2
{
NSMutableData *result = [[NSMutableData alloc] initWithLength:5];
if (_tokenData) [self.class appendTo:result identifier:1 bytes:_tokenData.bytes length:_tokenData.length];
if (_payloadData) [self.class appendTo:result identifier:2 bytes:_payloadData.bytes length:_payloadData.length];
uint32_t identifier = htonl(_identifier);
uint32_t expires = htonl(_expirationStamp);
uint8_t priority = _priority;
if (identifier) [self.class appendTo:result identifier:3 bytes:&identifier length:4];
if (_addExpiration) [self.class appendTo:result identifier:4 bytes:&expires length:4];
if (priority) [self.class appendTo:result identifier:5 bytes:&priority length:1];
uint8_t command = 2;
[result replaceBytesInRange:NSMakeRange(0, 1) withBytes:&command];
uint32_t length = htonl(result.length - 5);
[result replaceBytesInRange:NSMakeRange(1, 4) withBytes:&length];
return result;
}

@leonardvandriel Could you explain how do you know the identifier 5 is related with the priority?

@ricardopereira
Copy link

Ok, after some googling, I found out that this project is using the Binary Provider API a legacy binary interface which Apple wants to deprecate in prol of the HTTP/2-based API:

All developers should migrate their remote notification provider servers to the more capable and more efficient HTTP/2-based API described in Communicating with APNs.

There's a table with all the table possible identifier's called Table A-3. Unfortunately, there's no Item ID to reflect the new requirement of setting the contents of the notification’s payload (background or the default alert) 😞, so the solution is:

  1. migrate this to HTTP/2-based API;
  2. deprecate this project and use, for example: https://github.com/KnuffApp/Knuff.

@MMooreGitHub
Copy link

MMooreGitHub commented Oct 25, 2019 via email

@ricardopereira
Copy link

It's official https://developer.apple.com/news/?id=11042019a

If you send push notifications with the legacy binary protocol, we recommend updating to the HTTP/2-based APNs provider API as soon as possible. You’ll be able to take advantage of great modern features, such as authentication with a JSON Web Token, improved error messaging, and per-notification feedback.
The Apple Push Notification service (APNs) will no longer support the legacy binary protocol as of November 2020.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants