gpt4 book ai didi

ios - Firebase 推送通知不适用于手机但适用于模拟器

转载 作者:可可西里 更新时间:2023-11-01 02:16:29 25 4
gpt4 key购买 nike

我正在尝试让我的远程推送通知在我的手机上运行。当我将手机连接到计算机并通过手机运行模拟器时,从 Firebase 控制台发送的通知工作得很好。但是,当我将它上传到 Testflight 并将其下载到我的手机上时,我的推送通知没有通过。

我的证书已正确上传,下面是我的代码

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

override init() {
FIRApp.configure()
FIRDatabase.database().persistenceEnabled = true
}

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let notificationTypes : UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
let notificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
application.registerForRemoteNotifications()
application.registerUserNotificationSettings(notificationSettings)

return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}

func application(application: UIApplication,
openURL url: NSURL,
sourceApplication: String?,
annotation: AnyObject) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(
application,
openURL: url,
sourceApplication: sourceApplication,
annotation: annotation)
}

func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
FBSDKAppEvents.activateApp()
}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification

// Print message ID.
print("Message ID: \(userInfo["gcm.message_id"]!)")

// Print full message.
print("%@", userInfo)

completionHandler(.NoData)
}


func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
print(error)
print(error.description)
}
}

enter image description here

最佳答案

您是否创建了 APNs 分发证书并提交到 Firebase 控制台?

请查看本指南: https://firebase.google.com/docs/cloud-messaging/ios/certs#configure_an_app_id_for_push_notifications

“该应用现已启用使用推送通知开发环境。当您准备好发布您的应用时,您需要启用该应用以使用推送通知生产环境:重复这些步骤,但单击创建Production SSL Certificate 部分下的证书而不是 Development SSL Certificate。如果您正在调用 setAPNSToken,请确保类型的值已正确设置:沙箱环境为 FIRInstanceIDAPNSTokenTypeSandbox,生产环境为 FIRInstanceIDAPNSTokenTypeProd。如果您没有设置正确的类型,消息将不会传送到您的应用。”

关于ios - Firebase 推送通知不适用于手机但适用于模拟器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38026595/

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