gpt4 book ai didi

ios - 如何在 Swift 中从我的应用程序检索通知

转载 作者:行者123 更新时间:2023-11-30 12:52:02 24 4
gpt4 key购买 nike

我有多个登录用户,每个用户都可以在他的位置添加警报。此警报将存储在 Firebase 数据库中。

问题

问题是,如果用户所在区域发布了警报,我应该如何做才能让用户收到通知。

alerts Firebase node

users Firebase node

最佳答案

IOS 9及以上版本使用方法:

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

// Print message ID.
print("Message ID: \(userInfo["gcm.message_id"]!)")

// Print full message.
print(userInfo)
}

在函数中解析并处理这些数据。 在 iOS 10+ 中在 appdelegate header 中使用 import UserNotification 并输入此方法

@available(iOS 10, *)
extension HyberFirebaseMessagingDelegate : UNUserNotificationCenterDelegate {
// Receive displayed notifications for iOS 10 devices.
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
print(userInfo)//print user info
}
}

extension HyberFirebaseMessagingDelegate : FIRMessagingDelegate {
// Receive data message on iOS 10 devices.
func applicationReceivedRemoteMessage(_ remoteMessage: FIRMessagingRemoteMessage) {
print("%@", remoteMessage.appData)
}
}

更多详情您可以阅读here

关于ios - 如何在 Swift 中从我的应用程序检索通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40838617/

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