小编iob*_*any的帖子

如何从iOS 10和Swift 3中的Firebase控制台发送推送通知的正文?

我正在开发一个iOS应用程序,它应该接收从Firebase控制台发送的推送通知.我正在使用Swift 3和iOS 10.

根据Firebase文档的建议,在我们的应用程序完成启动之前,我们必须将我们的委托对象分配给UNUserNotificationCenter对象以接收和显示通知,以及FIRMessaging接收数据消息的对象.

这已经在该didFinishLaunchingWithOptions方法中完成.我按照所有步骤来配置Firmessaging以及APN.

现在,当我从Firebase控制台发送消息时,我通过applicationReceivedRemoteMessage(_ remoteMessage: FIRMessagingRemoteMessage)方法接收消息.

问题是我无法从remoteMessage.appData字典中提取消息的正文.知道身体在内remoteMessage.appData["notification"].的确,指示

print(remoteMessage.appData)
Run Code Online (Sandbox Code Playgroud)

版画

[AnyHashable("notification"): {
   body = Hello Notifications;
   e = 1;
}, AnyHashable("from"): 49679924394, AnyHashable("collapse_key"): com.company.app]
Run Code Online (Sandbox Code Playgroud)

印花

 remoteMessage.appData["notification"]
Run Code Online (Sandbox Code Playgroud)

节目

{
   body = Hello Notifications;
   e = 1;
}
Run Code Online (Sandbox Code Playgroud)

我试过了

remoteMessage.appData["notification"]["body"]
Run Code Online (Sandbox Code Playgroud)

 remoteMessage.appData["notification"].body
Run Code Online (Sandbox Code Playgroud)

但它会导致语法错误.我无法提取身体以便在警报控制器中显示它.appDelegate的代码如下.

class AppDelegate: UIResponder, UIApplicationDelegate, FIRMessagingDelegate, UNUserNotificationCenterDelegate{
......

func application(_ application: UIApplication, didFinishLaunchingWithOptions, launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    application.isStatusBarHidden = true
    FIRApp.configure()
    FIRDatabase.database().persistenceEnabled = true
    if …
Run Code Online (Sandbox Code Playgroud)

ios firebase swift3 firebase-notifications ios10

6
推荐指数
1
解决办法
5104
查看次数

标签 统计

firebase ×1

firebase-notifications ×1

ios ×1

ios10 ×1

swift3 ×1