[英]Stopped receiving firebase notifications completely suddenly
我正在為工作中的應用程序設置iOS 12推送通知。 他們在開始的前兩天工作良好,然后突然完全停止。 我無權訪問Firebase服務器。 我通過帖子發送api密鑰和設備ID,然后網絡應用在服務器上注冊了該設備。 第一次安裝時,它對我來說非常理想,然后突然間,它完全停止了工作。 由於某種原因,它可以完美地在Android上運行。
我嘗試了很多解決方案,但實際上沒有任何效果,除了未設置apns令牌外,當我未設置apns令牌時,firebase didrecievemessage會被調用,但蘋果默認值不會被調用。 如果我設置了APNS令牌didReceive remoteMessage不會被調用! 我沒有任何錯誤。 下面的代碼經過了很多次,即使簽出之前可以工作的版本也無濟於事。 appcoord是設置我的視圖控制器的類。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
appCoord.start()
UNUserNotificationCenter.current().delegate = self
application.registerForRemoteNotifications()
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {result,error in print(result,error) })
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
InstanceID.instanceID().deleteID{ error in
Messaging.messaging().setAPNSToken(deviceToken, type: .prod)
Messaging.messaging().delegate = self
Messaging.messaging().shouldEstablishDirectChannel = true
}
}
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
print("Firebase registration token: \(fcmToken)")
let dataDict:[String: String] = ["token": fcmToken]
NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
KeychainProvider.setToken(token: fcmToken)
print(KeychainProvider.loadToken())
appCoord.updateToken()
Messaging.messaging().subscribe(toTopic: "news")
print("gottoken")
}
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
appCoord.updateInbox()
print("msg",remoteMessage)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
print("dobio je notifikaciju")
appCoord.updateInbox()
Messaging.messaging().appDidReceiveMessage(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
print("fjyfjdfj--------------------------------------")
completionHandler()
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let notificationType = UIApplication.shared.currentUserNotificationSettings?.types
print("push enabled")
// custom code to handle push while app is in the foreground
// print("Handle push from foreground\(notification.request.content.userInfo)")
let dict = notification.request.content.userInfo["aps"] as! NSDictionary
let d : [String : Any] = dict["alert"] as! [String : Any]
var body : String = d["body"] as! String
let title : String = d["title"] as! String
print("Title:\(title) + body:\(body)")
completionHandler([.alert,.badge,.sound])
}
如果它以前工作並且突然停止,則可能是一種特定情況,如果您在開發和生產期間在同一iOS設備上對其進行測試。 如果收到實際的生產通知,它可能會停止開發。 如果是這樣,請改為在尚未用於此應用程序的iOS設備上嘗試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.