gpt4 book ai didi

ios - 云消息处理终止应用程序

转载 作者:IT王子 更新时间:2023-10-29 05:11:59 26 4
gpt4 key购买 nike

我有一个将用户 session 存储在 NSUserDefaults 中的应用程序。当应用程序被强制关闭时,在初始验证数据 Controller 用户 session 是否存在,如果存在则将其发送到启动窗口如下:

override func viewWillAppear(animated: Bool) {

self.view.hidden = true

let defaults = NSUserDefaults.standardUserDefaults()
if defaults.stringForKey("user") != nil
{

dispatch_async(dispatch_get_main_queue(), { () -> Void in
let viewController:UIViewController = self.storyboard?.instantiateViewControllerWithIdentifier("vistaInicio") as! ViewControllerInicio
self.presentViewController(viewController, animated: true, completion: nil)
})


}else
{
self.view.hidden = false

}

}

直到今天,当我决定按照本教程 Setting up a Firebase Cloud Messaging Client App on iOS 更新 firebase 来实现推送通知时,这对我来说一直很顺利。 .当他杀死应用程序并再次输入时出现问题,并给出以下错误代码:

 2016-05-19 16:05:27.647: <FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(full)"
2016-05-19 16:05:27.659: <FIRMessaging/INFO> FIRMessaging library version 1.1.0
2016-05-19 16:05:27.831: <FIRMessaging/WARNING> FIRMessaging registration is not ready with auth credentials
Unable to connect with FCM. Optional(Error Domain=com.google.fcm Code=501 "(null)")

Screenshot

最佳答案

这是解决方案,

首先在 Firebase 控制台中上传必要的证书然后在您的应用中启用推送通知和后台模式 -> 远程通知

之后在 App Delegate 中使用下面的代码(我指定了棘手的行):

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
registerForPushNotifications(application)
// Override point for customization after application launch.
// Use Firebase library to configure APIs
FIRApp.configure()
return true
}

func registerForPushNotifications(application: UIApplication) {
let notificationSettings = UIUserNotificationSettings(
forTypes: [.Badge, .Sound, .Alert], categories: nil)
application.registerUserNotificationSettings(notificationSettings)
}

func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
if notificationSettings.types != .None {
application.registerForRemoteNotifications()
}
}

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

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

//Tricky line
FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Unknown)
print("Device Token:", tokenString)
}

关于ios - 云消息处理终止应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37333177/

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