Safari web push notifications APNS returns 200 status, but notification not delivered to device

Viewed 456

Issue

Sending Web Push Notifications to APNS returns a "200" OK status, but the notification never reaches my Mac computer.

Requesting permission to send Web Push Notifications

Created "Website push id" in developer.apple.com, wrote scripts to dynamically create the push package with all the appropriate hashes and signature.

In Angular app I request permission and get the device token per this:

  checkSafariPushPermission() : void{
    if ('safari' in window && 'pushNotification' in window.safari) {
      this.checkAppleWebPushNotificationsRemotePermission(window.safari.pushNotification.permission(this.appleWebsitePushId));
    }
  }


  checkAppleWebPushNotificationsRemotePermission(permissionData: AppleWebPushNotificationPermissionsData) : void {
    let webServiceURL = this.globalVarsService.apiUrl + 'apple_pushnotifications/';
    if (permissionData.permission === 'default') {
        // This is a new web service URL and its validity is unknown.
        window.safari.pushNotification.requestPermission(
            webServiceURL, // The web service URL.
            this.appleWebsitePushId, // The Website Push ID.
            { userId: this.globalVarsService.userId }, // Data that you choose to send to your server to help you identify the user.
            function(permissionData: AppleWebPushNotificationPermissionsData) {
              this.permissionSet(permissionData);
            }
        );
    }
    else if (permissionData.permission === 'denied' || permissionData.permission === 'granted') {
        this.permissionSet(permissionData);
    }else{
      this.utilsService.doAlert("There was a problem processing your permissions selection with Apple.");
    }
  };

  
  permissionSet(permissionData: AppleWebPushNotificationPermissionsData) : void{
    console.log("Permission " + permissionData.permission)
    console.log("Token", permissionData.deviceToken)
  }
 

On allowing permission this returns the permissionData.deviceToken correctly and the Push Package is added to my Mac so that I can see the web app listed in both Safari "Preferences > Websites > Notifications" where is shows with "Allow" selected. And also in the Notification Centre where I have all the options for "Banners" "Badges" etc.

So the permissions step appears to be working properly.

Sending Web Push Notifications

In developer.apple.com I created a Apple Push Notifications service key.

In python using the gobiko.apns library I compose

    client = APNsClient(
        team_id=APPLE_TEAM_ID,
        bundle_id=CERTIFICATE_NAME_FROM_P12_CERTIFICATE_ABOVE,
        auth_key_id=APPLE_WEB_PUSH_NOTIFICATION_APNS_KEYID,
        auth_key_filepath=APPLE_WEB_PUSH_NOTIFICATION_APNS_KEY_PATH,
        use_sandbox=False
    )

    client.send_message(
        'DEVICE_TOKEN_HERE',
        "This is my message"
    )

The code executes without error and if I print the response from APNS it gives a "200" status ok. No notification shows on the Mac computer and I can't see any way to debug.

I am unsure if it is correct to use the "name" of the Website Push certificate from developer.apple.com as the bundle_id.

I've also checked the do not disturb settings.

I am aware that delivery is not guaranteed, but I'm not sure if it's working at all.

Any debugging guidance would be appreciated. Thank you.

0 Answers
Related