gpt4 book ai didi

ios - Firebase 注册 token 无效。检查 token 格式

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:10:50 25 4
gpt4 key购买 nike

这个问题已经被问过和回答过很多次了,但我不知道我做错了什么。从 Firebase 控制台向整个应用程序发送通知是可行的,但如果我发送到单个 token ,我会在 firebase 控制台中收到错误消息:“Firebase 注册 token 无效。检查 token 格式”

我正在 Iphone 设备上测试该应用程序。

注意:在 developer.apple.com 的 APP ID 下,如果我单击 myApp id 并向下滚动,Push Notifications Configurable & Development 显示为黄色而不是绿色。

Xcode version Version 8.3.3 (8E3004b), Swift 3.0
pod file
pod 'Firebase', '~> 3.9.0'
pod 'Firebase/Auth', '~> 3.9.0'
pod 'Firebase/Database', '~> 3.9.0'
pod 'Firebase/Storage'
pod 'Firebase/Messaging'

Using Firebase (3.9.0)
Using FirebaseAnalytics (3.5.1)
Using FirebaseAuth (3.0.6)
Using FirebaseCore (3.4.4)
Using FirebaseDatabase (3.1.0)
Using FirebaseInstanceID (1.0.9)
Using FirebaseMessaging (1.2.1)
Using FirebaseStorage (1.0.4)
Using GTMSessionFetcher (1.1.12)
Using GoogleInterchangeUtilities (1.2.2)
Using GoogleSymbolUtilities (1.1.2)
Using GoogleToolboxForMac (2.1.3)



import UIKit
import Firebase
import FirebaseCore
import FirebaseMessaging
import FirebaseInstanceID
import UserNotifications

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


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

FIRApp.configure()

NotificationCenter.default.addObserver(self, selector: #selector(self.tokenRefreshNotification(notification:)), name: NSNotification.Name.firInstanceIDTokenRefresh, object: nil)

//obtain the user’s permission to show any kind of notification
registerForPushNotifications()
return true
}//end of didFinishLaunchingWithOptions


//obtain the user’s permission to show any kind of notification
func registerForPushNotifications() {

// iOS 10 support
if #available(iOS 10, *) {
UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .alert, .sound]){ (granted, error) in
print("Permission granted: \(granted)")

guard granted else {return}
self.getNotificationSettings()
}
}
// iOS 9 support
else if #available(iOS 9, *){UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: nil))
self.getNotificationSettings()
}
// iOS 8 support
else if #available(iOS 8, *) {UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: nil))
self.getNotificationSettings()
}
// iOS 7 support
else {
UIApplication.shared.registerForRemoteNotifications(matching: [.badge, .sound, .alert])
}
}//end of registerForPushNotifications()



//if user decliens permission when we request authorization to show notification
func getNotificationSettings() {
UNUserNotificationCenter.current().getNotificationSettings { (settings) in

print("settings.authorizationStatus is \(settings.authorizationStatus)")
guard settings.authorizationStatus == .authorized else {return}
UIApplication.shared.registerForRemoteNotifications()
}
}


func tokenRefreshNotification(notification: NSNotification) {
let refereshToken = FIRInstanceID.instanceID().token()
print("instance ID token is \(refereshToken)")
prints: c-_B0W1AKX0:APA91bHBCtFhGtteH1r2y7c8gpUJpfrgDZYtncFmxZQht_wBDWk9Stdf78aMqUctKYU_OlIkmMNW-KLP68_IhdZCM2WxcN4fU1XkoIVNCGTvBogzSpgt4IkveLbK7rNX7pQTfmP72MfV

connectToFcm()
}


func connectToFcm() {
FIRMessaging.messaging().connect { (error) in
if error != nil {
print("unable to connect to FCM")
}else {
print("connected to FCM")
}
}
}

}//end of AppDelegate

enter image description here enter image description here enter image description here enter image description here enter image description here

最佳答案

当我在 Firebase 控制台中创建应用程序时,我在填写 Bundle ID 时输错了一个字母。
我从来没有想过检查它,因为我一直在使用 Firebase 数据库服务并且所有 CRUD 操作都按预期工作,但是 Xcworkspace 中的 Bundle ID 和 firebase 应用程序的 BundleID 不完全相同。
如果来自 Google 的任何人都可以说出为什么即使 Firebase 控制台中的 bundleID 不正确,从客户端应用程序读取/写入仍按预期工作的原因,那就太好了。

我是怎么发现打字错误的?
最初我在 Firebase 控制台上传了从 developer.apple.com 下载的 p8 文件,没有显示错误。
后来,我决定使用证书(旧方法),当我尝试上传 Apple Push Notification service SSL (Sandbox) - Development 时出现错误 The certificate bundleId did not match that您的应用

关于ios - Firebase 注册 token 无效。检查 token 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50359010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com