gpt4 book ai didi

ios - 未调用 Swift didReceiveRemoteNotification

转载 作者:搜寻专家 更新时间:2023-10-30 22:30:49 31 4
gpt4 key购买 nike

我有一个使用 oneSignal 作为推送提供者的应用程序。我可以收到推送通知,效果很好。但是,如果我尝试访问推送负载,我将一无所获,因为未调用 didReceiveRemoteNotification

我有以下代码

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

if application.applicationState != UIApplicationState.Background {

let preBackgroundPush = !application.respondsToSelector("backgroundRefreshStatus")
let oldPushHandlerOnly = !self.respondsToSelector("application:didReceiveRemoteNotification:fetchCompletionHandler:")
var pushPayload = false
if let options = launchOptions {
pushPayload = options[UIApplicationLaunchOptionsRemoteNotificationKey] != nil
}

}
if application.respondsToSelector("registerUserNotificationSettings:") {
let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
} else {
let types : UIRemoteNotificationType = [.Badge, .Alert, .Sound]
application.registerForRemoteNotificationTypes(types)
}

}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {

if userInfo["d"] as! String == "t" {

print("key was received")

}
print(userInfo)
print("PREVED")

}

问题是当我收到推送时没有打印出来。我做错了什么?

最佳答案

在这个地方试试你的delegete方法

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {

叫这个

 func application(application: UIApplication,  didReceiveRemoteNotification userInfo: [NSObject : AnyObject],  fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {

print("Recived: \(userInfo)")

completionHandler(.NewData)

}

关于ios - 未调用 Swift didReceiveRemoteNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35724945/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com