部分iOS设备静默推送通知无法正常工作问题求助
iOS 15.3.1设备静默推送无日志问题
测试设备情况
- 静默推送正常:iOS 16.5.1 (c),iPhone Xs
- 静默推送失败:iOS 15.3.1,iPhone Xr
问题现象
两台设备均可正常接收普通提醒通知,但iOS 15.3.1的iPhone Xr在接收静默推送后,Swift项目中没有任何日志输出。
已完成的排查项
content-available已设置为1- 应用未处于终止状态,当前为前台或后台挂起状态
- 发送普通通知时,Swift项目可正常生成日志,设备接收正常
- 推送证书未过期(若证书存在问题,普通通知也无法正常接收)
- 设备未开启省电模式,且已在应用设置中开启“后台应用刷新”选项
- 两台设备均处于充电状态
- 应用已开启Background Modes权限,包含Remote Notifications、Background Fetch、Background Processing
CloudKit仪表板状态
发送静默推送后的状态:
Swift项目AppDelegate代码
import SwiftUI import UIKit import UserNotifications class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in if granted { DispatchQueue.main.async { UIApplication.shared.registerForRemoteNotifications() } } } return true } func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) } let token = tokenParts.joined() print("Device Token: \(token)") } func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { print("Failed to register: \(error)") } func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { logInfo("Received Push Notification: \(userInfo)") if let aps = userInfo["aps"] as? [String: AnyObject], aps["content-available"] as? Int == 1 { logInfo("This is a silent push notification") //DO SOME WORK completionHandler(.newData) } completionHandler(.newData) } }
内容的提问来源于stack exchange,提问作者Ozgur Baykal
相关产品推荐
相关产品推荐

