Tij*_*jme 16 macos apple-push-notifications swift
我正在运行一个 iOS 一次性密码 (OTP) 应用程序和一个相应的 MacOS 配套应用程序。在 iOS 应用程序中,用户可以点击一次性密码,从而导致 iOS 应用程序向我的服务器发送 HTTP 请求。我的服务器反过来会向 MacOS 应用程序发送一条推送通知,其中包含所点击的一次性密码。当然全部都是加密的,但这与问题无关。
iOS application -> HTTP request -> My server -> APS -> MacOS application
Run Code Online (Sandbox Code Playgroud)
最近,在用户开始升级到 MacOS Ventura 后,MacOS 应用程序停止接收通知。我可以看到(并且我已经验证)从 iOS 应用程序到服务器、再到 APS 的过程是有效的。APS 返回200 OK
成功状态,表明推送通知已发送到 MacOS 设备。
但是,在我的 MacOS 应用程序中,函数中未收到通知didReceiveRemoteNotification
(我将其包含在下面)。
/// 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.")
}
Run Code Online (Sandbox Code Playgroud)
该didRegisterForRemoteNotificationsWithDeviceToken
函数确实有效,并且由于我的应用程序的调试日志记录,我可以看到它成功了。
/// 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.")
}
Run Code Online (Sandbox Code Playgroud)
我已经验证我正在使用 APS 的实际生产密钥,并且 MacOS 应用程序本身也是生产版本(或者在我的例子中是 TestFlight)。在用户开始升级到 Ventura 之前,我使用了相同的生产密钥和版本,并且它始终有效。
有趣的是,虽然我在 Xcode 或应用程序生产版本的调试日志中看不到任何内容,但Console.app
MacOS 确实显示了正在接收的推送通知。我在下面包含了一些Console.app
APS 日志记录(从我的 MacOS 应用程序中应收到通知的时间开始)。
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)
Run Code Online (Sandbox Code Playgroud)
以下两行引起了我的注意,以及我的应用程序的其他一些用户在调试该问题时的注意。
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)
Run Code Online (Sandbox Code Playgroud)
但是,在互联网上搜索这些错误消息不会产生任何(有用的)结果。因此,我想在 StackOverflow 上向您寻求帮助!
欢迎就我为何在 MacOS 应用程序中无法正确接收这些通知提出任何想法。希望我们能够找到解决方案。
由于我的应用程序是开源的,因此查看代码可能会很有用。我添加了下面的 Github 项目的链接。
对于我的应用程序的推送通知正在工作的用户,以下日志记录在 中可见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)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1477 次 |
最近记录: |