我需要處理推送通知,並使用較低版本的ios完成,但在ios 11中從未收到任何推送通知。我使用Firebase雲消息傳遞。請任何人有解決方案,然後請分享。FCM推送通知不適用於iOS 11
1
A
回答
4
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Use Firebase library to configure APIs
FirebaseApp.configure()
self.registerForPushNotifications(application: application)
Messaging.messaging().delegate = self
if let token = InstanceID.instanceID().token() {
NSLog("FCM TOKEN : \(token)")
DataModel.sharedInstance.onSetUserFCMStringToken(FCM: token)
self.connectToFcm()
}
if launchOptions != nil {
//opened from a push notification when the app is closed
_ = launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] as? [AnyHashable: Any] ?? [AnyHashable: Any]()
}
else {
//opened app without a push notification.
}
return true
}
@available(iOS版10,*)
extension AppDelegate: UNUserNotificationCenterDelegate {
// iOS10+, called when presenting notification in foreground
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
NSLog("[UserNotificationCenter] willPresentNotification: \(userInfo)")
//TODO: Handle foreground notification
completionHandler([.alert])
}
// iOS10+, called when received response (default open, dismiss or custom action) for a notification
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping() -> Void) {
let userInfo = response.notification.request.content.userInfo
NSLog("[UserNotificationCenter] didReceiveResponse: \(userInfo)")
//TODO: Handle background notification
completionHandler()
}}
extension AppDelegate : MessagingDelegate {
//MARK: FCM Token Refreshed
func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
NSLog("[RemoteNotification] didRefreshRegistrationToken: \(fcmToken)")
}
// Receive data message on iOS 10 devices while app is in the foreground.
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
NSLog("remoteMessage: \(remoteMessage.appData)")
}}
//Register for push notification.
func registerForPushNotifications(application: UIApplication) {
if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
center.delegate = self
center.requestAuthorization(options: [.alert,.sound]) { (granted, error) in
if error == nil{
DispatchQueue.main.async(execute: {
application.registerForRemoteNotifications()
})
}
}
}
else {
let settings = UIUserNotificationSettings(types: [.alert,.sound], categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
}
// Add observer for InstanceID token refresh callback.
NotificationCenter.default.addObserver(self, selector: #selector(self.tokenRefreshNotification), name: NSNotification.Name.InstanceIDTokenRefresh, object: nil)
}
@objc func tokenRefreshNotification(_ notification: Notification) {
print(#function)
if let refreshedToken = InstanceID.instanceID().token() {
NSLog("Notification: refresh token from FCM -> \(refreshedToken)")
}
// Connect to FCM since connection may have failed when attempted before having a token.
connectToFcm()
}
func connectToFcm() {
// Won't connect since there is no token
guard InstanceID.instanceID().token() != nil else {
NSLog("FCM: Token does not exist.")
return
}
Messaging.messaging().shouldEstablishDirectChannel = true
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
NSLog("Notification: Unable to register for remote notifications: \(error.localizedDescription)")
}
// This function is added here only for debugging purposes, and can be removed if swizzling is enabled.
// If swizzling is disabled then this function must be implemented so that the APNs token can be paired to the InstanceID token.
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
}
// iOS9, called when presenting notification in foreground
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
NSLog("didReceiveRemoteNotification for iOS9: \(userInfo)")
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
}
1
問題似乎是與
FirebaseInstanceID版本低於1.0.9
FirebaseInstanceID版本2.0.1之間 - 2.0.3
設置你的POD文件,如下:
爲SWIFT 2.3和Xcode中8:(FirebaseInstanceID V1.1.0被安裝)
pod 'Firebase/Core', '3.8.0'
pod 'Firebase/Messaging'
用於SWIFT 3和Xcode的9:
pod 'Firebase/Core'
pod 'Firebase/Messaging'
pod 'FirebaseInstanceID', "2.0.0
我不想升級到2.0.0 FirebaseInstanceID來解決這個問題,因爲我想用雨燕2.3只
相關問題
- 1. 推送通知不適用於ios 9.2.1
- 2. 推送通知不適用於iOS 4
- 3. GCM推送通知不適用於iOS
- 4. 推送通知不適用於iOS 5.0.1
- 5. 發送推送IOS上的FCM通知
- 6. 使用FCM的iOS推送通知
- 7. FCM推送通知
- 8. 推送通知不適用於使用cordova-plugin-fcm插件的iOS製作
- 9. 推送通知不適用於iOS 7,但適用於iOS8
- 10. iOS 10推送通知適用於gateway.sandbox.push.apple.com,但不適用於gateway.push.apple.com
- 11. iOS FCM沒有得到推送通知
- 12. FCM Web推送通知(Chrome)僅適用於桌面版
- 13. 基於Sinch FCM的推送通知
- 14. 基於位置的推送通知FCM
- 15. Android推送通知,fcm
- 16. FCM:跟蹤狀態FCM推送通知
- 17. 推送通知不適用於HTTPS
- 18. Apple推送通知不適用於aps_production.cer
- 19. 推送通知不適用於iphone
- 20. 推送通知不適用於生產
- 21. 推送通知不適用於ios上的發佈版本
- 22. Clevertap for IONIC推送通知不適用於IOS
- 23. iOS推送通知不適用於分配
- 24. Firebase推送通知不適用於iOS上的生產
- 25. ios推送通知不適用於城市飛艇
- 26. 通過gcm/fcm推送多個android和ios應用的通知
- 27. 推送通知不適用於iOS7,但它們適用於iOS6
- 28. 推送通知離子採用FCM
- 29. 使用FCM向Android推送通知(c#)
- 30. 使用FCM和php推送通知
哎,我習慣FirebaseInstanceID」,「2.0。 0「,甚至最新的豆莢,但沒有得到通知,你能指導我,如何修復這個 –
很多搜索後,我只是使用最新版本或默認版本的豆莢,然後檢查這是在我身邊的工作有證書問題或某些時候FCM令牌問題PLZ檢查 –
我正在使用的Pem文件正在其他在線門戶中工作。我已經在FCM中添加了,但在這裏顯示消息已發送,但我沒有收到我的設備。現在的問題,我面臨 –