【发布时间】:2019-01-15 00:05:51
【问题描述】:
我正在使用 firebase 推送通知,我的应用订阅了一个主题,一切都很好。但我想知道如果通过通知是否可以显示通知。这是我的场景:
local_user_id = 10
var payload = {
notification: {
title: "hi",
body: "this is a notification",
sound: "default"
},
data: {
user_id: "1",
message: "you should pay $3020.25"
}
};
1) 控制用户是否登录 (true/false) 2)获取通知的消息数据并查看:
if (payload.data.user_id = local_user_id && is_login){
show_notification()
}
3) 显示通知
实际上我只有通知,没有更多,我是 firebase 新手,这是我的代码:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) {
(granted, error) in
}
application.registerForRemoteNotifications()
FirebaseApp.configure()
return true
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
let dict = userInfo["aps"] as! NSDictionary
let message = dict["alert"]
print("response")
print(message)
}
我不知道该怎么做,这可能吗? 提前致谢
【问题讨论】:
标签: ios swift firebase push-notification