Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silent push notification (background) not received on macOS Catalina (Catalyst app)

I'm currently implementing push notifications from our backend server to our app (macOS Catalina & iOS - same code base), using Apple Push Notifications & the token based way of authentication (generating JWT from keyId, teamId, ... & signing it with the private key generated in the Apple developer console) to send pushes to APN service.

The problem I am facing is that I can successfully send "alert" notifications (status 200, with header apns-push-type: alert) and receive them on my iOS and MacOS device (the push notifications appear successfully in production and sandbox mode) but for some reason, "silent" pushes (with header apns-push-type: background) are only received on my iOS device (iPhone), but not on my Mac (didReceiveRemoteNotification(...) in AppDelegate is never called).

What I have done so far:

  • Made sure APN request header is correctly configured for silent push: apns-push-type: background
  • Made sure to have the correct APN topic header: apns-topic: my.bundle.id (this is different for sandbox/production)
  • Added the "semi-required" priority header: apns-priority: 5 (only when delivering background pushes)
  • Verified that the created JWT is valid and used in the APN auth header: authorization: mytoken (this must be the case, otherwise APN service would not respond with status 200)
  • Confirmed that my application has the correct entitlements & capabilities defined in Xcode (my reasoning: this must be the case, otherwise 'alert' push notifications would also not work)
  • Double checked that push notifications for the Mac app are allowed/enabled (checked system settings)
  • Made sure the device token im sending the push to is actually from the device intended to receive the push (e.g. my MacBook)
  • Checked that the private key I'm using to sign the JWT has the APN capability
  • Tested while the Mac app is running but not in focus & also when in focus

The APNs requests I am performing to send the push are:

  • Sandbox: POST https://api.sandbox.push.apple.com/3/device/{deviceToken}
  • Production: POST https://api.push.apple.com/3/device/{deviceToken}

The payload (JSON) I'm sending to APN service in the request body looks as follows:

{
   "aps": {
      "content-available": 1 # defines push as "silent"
   },
   "data": { #some key-value pairs here }
}

In any case (both production & sandbox, both with the device token of iOS and macOS), my request to APN returns with a status code 200. My MacBook is running Catalina 10.15.3. What am I possibly doing wrong here or is that something that is simply not supported for Catalyst apps?

like image 893
Philipp Jahoda Avatar asked Feb 11 '20 08:02

Philipp Jahoda


People also ask

Will iOS awake my app when I receive silent push notification?

Yes. It will. When you click on that. Yeah its ok but being push notification is silent,you are not able to view any alert and cant click.

What is silent push notification?

They arrive on the mobile device and sit in the notification tray until read or dismissed. Users can choose to mute their notifications and receive silent push notifications instead of being alerted to every new push that arrives. They can activate this on iOS or Android from their individual settings pages.

How do I send silent push notifications?

There are two ways users can receive silent push notifications on Android. Users can long press on a notification to get an option to display notifications silently. Users can also enable silent notifications by heading to Settings > App & Notifications > Search for app and choose> Notifications, and turn it off.

Does Apple support push notifications?

Remote NotificationsCommunicate with Apple Push Notification service (APNs) and receive a unique device token that identifies your app. Use basic macOS command-line tools to send push notifications to Apple Push Notification service (APNs).


1 Answers

Wow doozy question. I'm reasonably familiar with APNs headaches but something popped out at me from the latest docs:

Additionally, the notification’s POST request should contain the apns-push-type header field with a value of background, and the apns-priority field with a value of 5. The APNs server requires the apns-push-type field when sending push notifications to Apple Watch, and recommends it for all platforms. For more information, see Create and Send a POST Request to APNs.

Does the priority 5 thing make a difference?

Also my usually attempt to fix these problems is to test in an archive as opposed to an Xcode build. AFAIK the prod push server can only send to App Store, ad-hoc, enterprise, or testflight builds, so if you're just building from Xcode I don't think you'd get any push notifications with production apns.

like image 144
Matthew Weldon Avatar answered Oct 10 '22 21:10

Matthew Weldon