相关疑难解决方法(0)

正确的方法来检索FCM的令牌 - iOS 10 Swift 3

我已经使用FirebaseAuth/FCM等实施了Firebase,并通过Firebase控制台成功发送了通知.

但是,我需要从我自己的应用服务器推送通知.

我想知道下面哪种方式是正确的方法来检索设备的注册ID: -

1)从didRegisterForRemoteNotificationWithDeviceToken中检索注册ID令牌

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    var token = ""

    for i in 0..<deviceToken.count {
        token += String(format: "%02.2hhx", arguments: [deviceToken[i]])
    }

    print("Registration succeeded!")
    print("Token: ", token)
    Callquery(token)

}
Run Code Online (Sandbox Code Playgroud)

2)从firebase检索注册令牌(基于检索当前注册令牌的Firebase文档)

let token = FIRInstanceID.instanceID().token()!
Run Code Online (Sandbox Code Playgroud)

我正在使用第一种方式,即使注册ID相应地存储在我的应用服务器数据库上也没有收到推送通知,我得到了这个CURL会话结果: -

{"multicast_id":6074293608087656831,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
Run Code Online (Sandbox Code Playgroud)

我还尝试了第二种方式,并在运行应用程序时遇到致命错误,如下所示: - 在此输入图像描述

如果有人能指出我正确的方式表示赞赏,谢谢!

ios firebase swift firebase-cloud-messaging

36
推荐指数
9
解决办法
5万
查看次数

Firebase InstanceId 未解析标识符 swift4

我最近更新了我的 SWIFT 应用程序 pod 文件,因此 firebase 版本现在更新为 5.2。现在在获取设备实例 ID 时出现以下错误。

let tokenId = InstanceID.instanceID().token()
Run Code Online (Sandbox Code Playgroud)

错误:使用未解析的标识符“InstanceID”

以前这段代码运行良好,我正在获取应用程序的实例 ID。

以下是我的 pod 文件的内容。

   # Uncomment the next line to define a global platform for your project
# platform :ios, '11.2'

target 'FirebaseChat' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for FirebaseChat

pod 'Firebase/Database'
pod 'Firebase/Auth'
pod 'Firebase/Storage'
pod 'UnderLineTextField', '~> 2.0'
pod 'Alamofire'
pod 'TCPickerView'
pod 'Toast-Swift', '~> …
Run Code Online (Sandbox Code Playgroud)

ios firebase swift firebase-cloud-messaging

6
推荐指数
3
解决办法
4066
查看次数

标签 统计

firebase ×2

firebase-cloud-messaging ×2

ios ×2

swift ×2