gpt4 book ai didi

ios - didReceiveRemoteNotification 未调用 Swift

转载 作者:行者123 更新时间:2023-11-30 14:15:06 37 4
gpt4 key购买 nike

由于某种原因,我的 didReceiveRemoteNotification 从未被调用。我已完成以下操作:

APNS list :

创建允许推送通知的 AppId

使用有效证书和应用 ID 创建 SSL 证书

使用相同的证书创建配置文件并确保添加设备

带有代码:

注册应用程序以接收推送通知

处理didRegisterForRemoteNotificationsWithDeviceToken方法

设置目标> 功能> 后台模式> 远程通知处理didReceiveRemoteNotification

但是我的函数似乎没有被调用。我的代码如下所示:

  func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.

if (application.respondsToSelector("isRegisteredForRemoteNotifications"))
{
// iOS 8 Notifications
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: (.Badge | .Sound | .Alert), categories: nil));
application.registerForRemoteNotifications()
}
else
{
// iOS < 8 Notifications
application.registerForRemoteNotificationTypes(.Badge | .Sound | .Alert)
}


return true
}


func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let tokenChars = UnsafePointer<CChar>(deviceToken.bytes)
var tokenString = ""

for var i = 0; i < deviceToken.length; i++ {
tokenString += String(format: "%02.2hhx", arguments: [tokenChars[i]])
}

apnsID = tokenString
println("******apnsID is \(apnsID)")
dToken = deviceToken
println("******dToken is \(dToken)")
NSUserDefaults.standardUserDefaults().setObject(deviceToken, forKey: "deviceToken")
}

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
println("***********didFailToRegisterForRemoteNotificationsWithError")
println(error)
}

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

println("Getting notification")

var message: NSString = ""
var alert: AnyObject? = userInfo["aps"]

println(userInfo["aps"])

if((alert) != nil){
var alert = UIAlertView()
alert.title = "Title"
alert.message = "Message"
alert.addButtonWithTitle("OK")
alert.show()
}

}

最佳答案

在您的请求中添加content_available:true。用于 iOS 负载数据。您将在 didReceiveRemoteNotification 中收到通知。现在处理它。

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

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