【发布时间】:2020-09-27 06:39:14
【问题描述】:
我正在试用 Firebase 云消息传递。在这一点上,我已经阅读了一些相关文档,但我没有任何工作。
我已经为此设置了一个 iOS 应用和一个 Firebase 项目。
看着这个GitHub sample,我有个问题。
这行代码是按原样使用,还是占位符,我应该用我的某个 ID 替换 "gcm.message_id"? (如果是,是什么?)
let gcmMessageIDKey = "gcm.message_id"
更详细的,代码如下:
....
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let gcmMessageIDKey = "gcm.message_id"
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
// [START set_messaging_delegate]
Messaging.messaging().delegate = self
// [END set_messaging_delegate]
.......
然后gcmMessageIDKey在后面的代码中使用,像这里:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification
// With swizzling disabled you must let Messaging know about the message, for Analytics
// Messaging.messaging().appDidReceiveMessage(userInfo)
// Print message ID.
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
// Print full message.
print(userInfo)
}
我想知道,因为我已经尝试在我自己的应用程序中包含一些这样的代码,这似乎是有意义的。然后从 Firebase 控制台 Cloud Messaging 尝试发送测试消息。 但根本没有任何效果。
非常欢迎任何相关的提示,即使是很小的相关提示。
【问题讨论】:
-
请编辑问题以显示完整的代码示例。随着时间的推移,外部链接可能会发生变化或失效,这将使这个问题在未来对其他人没有帮助。
-
我刚刚编辑了问题。
标签: ios swift firebase firebase-cloud-messaging