I'm running an iOS one-time password (OTP) application, and a corresponding MacOS companion app. In the iOS application, users are able to tap on one-time passwords, resulting in the iOS application sending an HTTP request to my server. My server in turn, will send a push notification to the MacOS application, containing the tapped one-time password. All encrypted of course, but that's irrelevant for the issue.
iOS application -> HTTP request -> My server -> APS -> MacOS application
Recently, after users started upgrading to MacOS Ventura, the MacOS application stopped receiving notifications. I can see (and I've verified) that the process from the iOS application to the server, to APS works. APS returns a 200 OK
success status, indicating that the push notification was sent to the MacOS device.
However, in my MacOS application the notification is not received in the didReceiveRemoteNotification
function (which I included below).
/// Sent to the delegate when a running application receives a remote notification.
///
/// - Parameter application: The application that received the remote notification.
/// - Parameter userInfo: A dictionary that contains information related to the remote notification, specifically a badge number for the application icon, a notification identifier, and possibly custom data.
func application(_ application: NSApplication, didReceiveRemoteNotification userInfo: [String : Any]) {
NotificationHelper.shared.notify(userInfo)
log.verbose("Received a remote notification in the application delegate.")
}
The didRegisterForRemoteNotificationsWithDeviceToken
function does work, and I can see it succeeded because of my applications' debug logging.
/// Sent to the delegate when Apple Push Services successfully completes the registration process.
///
/// - Parameter application: The application that initiated the remote-notification registration process.
/// - Parameter deviceToken: A token that identifies the device to Apple Push Notification Service (APNS).
func application(_ application: NSApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
settingsView.pushToken.data = deviceToken
linkingView.pushToken.data = deviceToken
log.verbose("Successfully completed APNS registration process.")
}
I've verified that I'm using an actual production key for APS, and that the MacOS application itself is a production build as well (or well, TestFlight in my case). I used the same production key and build before users started upgrading to Ventura, and it always worked.
What's interesting is that, although I can't see anything in Xcode or in my debug logging of the production build of the app, the Console.app
of MacOS does show the push notification being received. I've included some of the Console.app
APS logging (from when a notification should be received in my MacOS application) below.
default 20:35:11.555463+0100 apsd <private>: Outstanding data received: <private> (length 490)
default 20:35:11.555624+0100 apsd <private>: Stream processing: complete yes, invalid no, length parsed 490, parameters <private>
default 20:35:11.555761+0100 apsd <private>: Failed to find token name for unrecognized token <private>
default 20:35:11.555876+0100 apsd <private>: Message has token <private> (tokenName (null))
error 20:35:11.556008+0100 apsd <private>: Received message for unknown token '<private>'
error 20:35:11.556068+0100 apsd <private>: Ignoring duplicate message received with topic: '<private>' timestamp=1671564911431255965 (57.5 seconds ago)
default 20:35:11.556186+0100 apsd APSPowerLog: {event: <private>, dict: <private>}
default 20:35:11.556432+0100 apsd <private>: Sending acknowledgement message with response 7 and messageId <private> (3889788835)
default 20:35:11.556591+0100 apsd <private>: Sending Push ACK. UUID: (null)
default 20:35:11.556735+0100 apsd <private>: Stream processing: complete no, invalid no, length parsed 0, parameters (null)
The following two lines caught my eye, and those of some other users of my app debugging the issue.
error 20:35:11.556008+0100 apsd <private>: Received message for unknown token '<private>'
error 20:35:11.556068+0100 apsd <private>: Ignoring duplicate message received with topic: '<private>' timestamp=1671564911431255965 (57.5 seconds ago)
However, searching for these error message on the internet does not yield any (helpful) results. Therefore, I would like to ask you on StackOverflow for help!
Any ideas on why I'm not receiving these notifications correctly in my MacOS app are welcome. Hopefully we can get to a solution.
As my apps are open-source, it might be useful to take a look at the code. I've added links to the Github projects below.
For users of my app where push notifications are working, the following logging is visible in Console.app
.
default 16:00:48.398808+0100 apsd <private>: Message has token <private> (tokenName <private>)
default 16:00:48.398969+0100 apsd <private>: Received message for enabled topic '<private>' onInterface: NonCellular with payload '<private>' with priority 5
default 16:00:48.399208+0100 apsd <private>: Push has been read from stream and parsed. UUID: (null)
default 16:00:48.399323+0100 apsd APSPowerLog: {event: <private>, dict: <private>}
default 16:00:48.399481+0100 apsd <private> asked to store incoming message <private> with guid <private> environment <private>
default 16:00:48.401221+0100 apsd APSMessageStore - New message record [<private>] has ID [16196].
default 16:00:48.401381+0100 apsd <private>: Sending acknowledgement message with response 0 and messageId <private> (37785720)
default 16:00:48.401473+0100 apsd <private>: Sending Push ACK. UUID: (null)
apsd
should be keeping thedeviceToken
list locally , the usual risks of cache corruption (and rarelyamplified by an upgrade event), could be creating problems on your test Mac. – Dashtilut