Swift 不会打印来自通知委托的负载
Swift will not print payload from notification delegate
我无法打印来自 did receive remote notification.I 在我的物理设备上收到通知的委托,但是当我尝试访问负载时,没有任何反应。我导入 import UserNotifications
我也 link 用户通知库,但这无济于事我不确定我在错什么。我使用一个信号,但这不应该导致接收通知方法不起作用。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
setupViewApDelegate()
application.statusBarStyle = .lightContent
//facebook login
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
//APIkeys().oneSignal
let onesignalInitSettings = [kOSSettingsKeyAutoPrompt: false]
OneSignal.initWithLaunchOptions(launchOptions,
appId: APIkeys().oneSignal,
handleNotificationAction: nil,
settings: onesignalInitSettings)
OneSignal.inFocusDisplayType = OSNotificationDisplayType.notification;
OneSignal.promptForPushNotifications(userResponse: { accepted in
print("User accepted notifications: \(accepted)")
})
return true
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
print("Push notification received: \(userInfo)")
}
看来我必须在 oneSignal 闭包中检索有效载荷
OneSignal.initWithLaunchOptions(launchOptions, appId: APIkeys().oneSignal, handleNotificationReceived: { (notification) in
let payload: OSNotificationPayload? = notification?.payload
let fullMessage: String? = payload?.body
print("Recived no" + fullMessage!)
print("Received Notification - \(notification?.payload.notificationID) - \(notification?.payload.title)")
}, handleNotificationAction: nil, settings: [kOSSettingsKeyAutoPrompt : false, kOSSettingsKeyInAppAlerts : false])
OneSignal.promptForPushNotifications(userResponse: { accepted in
print("User accepted notifications: \(accepted)")
})
OneSignal.inFocusDisplayType = OSNotificationDisplayType.notification;
我无法打印来自 did receive remote notification.I 在我的物理设备上收到通知的委托,但是当我尝试访问负载时,没有任何反应。我导入 import UserNotifications
我也 link 用户通知库,但这无济于事我不确定我在错什么。我使用一个信号,但这不应该导致接收通知方法不起作用。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
setupViewApDelegate()
application.statusBarStyle = .lightContent
//facebook login
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
//APIkeys().oneSignal
let onesignalInitSettings = [kOSSettingsKeyAutoPrompt: false]
OneSignal.initWithLaunchOptions(launchOptions,
appId: APIkeys().oneSignal,
handleNotificationAction: nil,
settings: onesignalInitSettings)
OneSignal.inFocusDisplayType = OSNotificationDisplayType.notification;
OneSignal.promptForPushNotifications(userResponse: { accepted in
print("User accepted notifications: \(accepted)")
})
return true
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
print("Push notification received: \(userInfo)")
}
看来我必须在 oneSignal 闭包中检索有效载荷
OneSignal.initWithLaunchOptions(launchOptions, appId: APIkeys().oneSignal, handleNotificationReceived: { (notification) in
let payload: OSNotificationPayload? = notification?.payload
let fullMessage: String? = payload?.body
print("Recived no" + fullMessage!)
print("Received Notification - \(notification?.payload.notificationID) - \(notification?.payload.title)")
}, handleNotificationAction: nil, settings: [kOSSettingsKeyAutoPrompt : false, kOSSettingsKeyInAppAlerts : false])
OneSignal.promptForPushNotifications(userResponse: { accepted in
print("User accepted notifications: \(accepted)")
})
OneSignal.inFocusDisplayType = OSNotificationDisplayType.notification;