Swift不会从通知委托中打印有效负载

时间:2017-05-28 12:46:50

标签: ios swift xcode onesignal

我无法打印代表从收到远程通知。我在我的物理设备上收到通知但是当我尝试访问有效载荷时没有任何反应。我导入import UserNotifications我还链接了用户通知库,但这无助于我不确定错误中的im。我使用一个信号,但不应该导致确实接收通知方法不起作用。

 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)")
    }

1 个答案:

答案 0 :(得分:0)

看起来我必须检索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;