ios - Firebase 消息传递 iOS 14
问题描述
我已经在我的应用程序中设置了 Firebase Cloud Messaging 有一段时间了。我最近将我的一台设备更新到 iOS 14,并停止在该设备上接收它们。装有 iOS 13 的不同设备仍会收到它们。如果这是一个愚蠢的问题,我很抱歉哈哈,但这是我的应用程序代表:
let appDelegate : AppDelegate = UIApplication.shared.delegate as! AppDelegate
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate {
var customerId = ""
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
application.registerForRemoteNotifications()
FirebaseApp.configure()
// Update this to your stripe PUBLISHABLE KEY
STPPaymentConfiguration.shared().publishableKey = "private"
let apiToken = "private"
EasyPostApi.sharedInstance.setCredentials(apiToken, baseUrl: "https://api.easypost.com/v2/")
STPTheme.default().accentColor = .red
Messaging.messaging().delegate = self
return true
}
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
print(userInfo)
print("test")
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
print(userInfo)
print("test")
completionHandler(UIBackgroundFetchResult.newData)
}
func registerForPushNotifications() {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
// For iOS 10 data message (sent via FCM
Messaging.messaging().delegate = self
InstanceID.instanceID().instanceID { (result, error) in
if let error = error {
print("Error fetching remote instance ID: \(error)")
} else if let result = result {
print("Remote instance ID token: \(result.token)")
}
}
}
}
我尝试使用firebase控制台中的“测试”按钮发送消息,并像正常一样发布消息。它确实正确注册了通知,并且在检查设置后,它看起来仍然正确。
解决方案
我有同样的问题。我现在发现的一个修复是禁用方法混合:
- 在您的 iOS 应用 Info.plist 中,添加
FirebaseAppDelegateProxyEnabled
并将其设置为 FALSE(布尔值 0)
看起来你已经didRegisterForRemoteNotificationsWithDeviceToken
设置好了,所以保持原样。
希望这可以帮助!
推荐阅读
- python - 通过匹配从张量中删除行
- eclipse - 如何在 Eclipse e4 应用程序的菜单/工具栏中创建切换/收音机项目?
- python - 数据类型“float128”不理解
- javascript - JS 项目中的 FB.logout 给出错误“表达式的类型未定义,不是函数”
- amazon-web-services - DynamoDB 上的 transactWrite 不是跨多个表的 ACID
- python - 时间序列数据趋势
- python - 调用了多少次 teardown_appcontext ?
- html5-video - HLS 播放器:单击时清除 video.js 缓冲区
- ffmpeg - 应用印地语字体文件或其他语言字体文件时出现FFmpeg drawtext问题
- python - Pandas 按条件分组和变换并应用于整列