Firebase FCM 未显示在我的 iphone 上
Firebase FCM not displaying on my iphone
我的 iPhone X 上没有显示 Firebase FCM 推送通知。我尝试使用带有 FirebaseInstanceID 2.0.0、2.0.6 和 2.0.7 的 firebase messaging 2.0.7 none工作过。我在第一次安装应用程序时获得了 fcmtoken,仅此而已。我是 运行 ios 11.2.1 使用 swift 4 xcode 9.
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()
}
我可以通过创建一个新的 xcode 项目并转移我的代码和故事板来解决它。看来问题是我之前设置了一个信号。
我的 iPhone X 上没有显示 Firebase FCM 推送通知。我尝试使用带有 FirebaseInstanceID 2.0.0、2.0.6 和 2.0.7 的 firebase messaging 2.0.7 none工作过。我在第一次安装应用程序时获得了 fcmtoken,仅此而已。我是 运行 ios 11.2.1 使用 swift 4 xcode 9.
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()
}
我可以通过创建一个新的 xcode 项目并转移我的代码和故事板来解决它。看来问题是我之前设置了一个信号。