0

Firebase FCM 推送通知没有显示在我的 iPhone X 上。我尝试使用 Firebase 消息传递 2.0.7,FirebaseInstanceID 为 2.0.0、2.0.6 和 2.0.7 均无效。我在第一次安装应用程序时获得了 fcmtoken,仅此而已。我正在使用 swift 4 xcode 9 运行 ios 11.2.1。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    UINavigationBar.appearance().barTintColor = .white
    UINavigationBar.appearance().tintColor = UIColor(red:0.93, green:0.22, blue:0.29, alpha:1.0)
    attemptNotificationRegistration(application: application) }

override init() {
    super.init()
    FirebaseApp.configure()
    Database.database().isPersistenceEnabled = true
}

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    print("Registered for notif: ", deviceToken)
}

func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {

    print("Registered with FCM with token:", fcmToken)

}

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    completionHandler(.alert)
}

private func attemptNotificationRegistration(application: UIApplication) {
    print("Attempting to register APNS...")

    Messaging.messaging().delegate = self
    UNUserNotificationCenter.current().delegate = self

    let options: UNAuthorizationOptions = [.alert, .badge, .sound]
    UNUserNotificationCenter.current().requestAuthorization(options: options) { (granted, error) in
        if let error = error {
            alerts().errorAlert(title: "Error", message: error.localizedDescription, duration: 0)
            return
        }

        if granted {
            print("Auth granted.")
        } else {
            print("Auth denied")
        }
    }

    application.registerForRemoteNotifications()
}
4

1 回答 1

0

我能够通过创建一个新的 xcode 项目并将我的代码和故事板转移过来来解决它。看起来问题是我以前有一个信号设置。

于 2017-12-15T12:56:41.220 回答