fix: 推送点击仅按 type 路由到收款页或消息中心。
对齐后端消息类型约定,去掉 route/uri 等兼容字段,并补充联调日志与单测。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -229,6 +229,7 @@ final class PushNotificationManager: NSObject {
|
||||
/// 处理 Scene 冷启动携带的系统通知响应,并向极光上报点击。
|
||||
func handleNotificationResponse(_ response: UNNotificationResponse) {
|
||||
let userInfo = response.notification.request.content.userInfo
|
||||
Self.logReceivedPush(userInfo, source: "tap(cold-start)")
|
||||
JPUSHService.handleRemoteNotification(userInfo)
|
||||
handleNotificationTap(
|
||||
payload: PushPayload(userInfo: userInfo),
|
||||
@ -238,10 +239,35 @@ final class PushNotificationManager: NSObject {
|
||||
|
||||
/// 处理后台静默通知并向极光上报到达,不触发页面跳转。
|
||||
func handleRemoteNotification(_ userInfo: [AnyHashable: Any]) {
|
||||
Self.logReceivedPush(userInfo, source: "background")
|
||||
JPUSHService.handleRemoteNotification(userInfo)
|
||||
NotificationCenter.default.post(name: NotificationName.unreadMessageCountDidChange, object: nil)
|
||||
}
|
||||
|
||||
/// 将收到的推送 payload 打印到控制台,便于联调排查。
|
||||
private nonisolated static func logReceivedPush(
|
||||
_ userInfo: [AnyHashable: Any],
|
||||
source: String
|
||||
) {
|
||||
#if DEBUG
|
||||
let payloadText: String
|
||||
let normalized = Dictionary(uniqueKeysWithValues: userInfo.compactMap { key, value in
|
||||
(key as? String).map { ($0, value) }
|
||||
})
|
||||
if JSONSerialization.isValidJSONObject(normalized),
|
||||
let data = try? JSONSerialization.data(
|
||||
withJSONObject: normalized,
|
||||
options: [.prettyPrinted, .sortedKeys]
|
||||
),
|
||||
let text = String(data: data, encoding: .utf8) {
|
||||
payloadText = text
|
||||
} else {
|
||||
payloadText = String(describing: userInfo)
|
||||
}
|
||||
print("[Push] received (\(source)):\n\(payloadText)")
|
||||
#endif
|
||||
}
|
||||
|
||||
private func observeJPushNetworkLogin() {
|
||||
NotificationCenter.default.addObserver(
|
||||
self,
|
||||
@ -352,7 +378,9 @@ extension PushNotificationManager: JPUSHRegisterDelegate {
|
||||
willPresent notification: UNNotification,
|
||||
withCompletionHandler completionHandler: @escaping (Int) -> Void
|
||||
) {
|
||||
JPUSHService.handleRemoteNotification(notification.request.content.userInfo)
|
||||
let userInfo = notification.request.content.userInfo
|
||||
Self.logReceivedPush(userInfo, source: "foreground")
|
||||
JPUSHService.handleRemoteNotification(userInfo)
|
||||
Task { @MainActor in
|
||||
NotificationCenter.default.post(name: NotificationName.unreadMessageCountDidChange, object: nil)
|
||||
}
|
||||
@ -367,6 +395,7 @@ extension PushNotificationManager: JPUSHRegisterDelegate {
|
||||
withCompletionHandler completionHandler: @escaping () -> Void
|
||||
) {
|
||||
let userInfo = response.notification.request.content.userInfo
|
||||
Self.logReceivedPush(userInfo, source: "tap")
|
||||
JPUSHService.handleRemoteNotification(userInfo)
|
||||
let payload = PushPayload(userInfo: userInfo)
|
||||
let requestIdentifier = response.notification.request.identifier
|
||||
|
||||
Reference in New Issue
Block a user