解密通知数据并在iOS -Flutter应用中使用数据

发布于 2025-01-31 07:27:19 字数 1342 浏览 1 评论 0原文

我正在Flutter应用程序中实施通知并检查iOS。方案是当用户在iOS中收到通知时,我想加密该数据以用于进一步的功能实现。这是我在appdelegate文件中

override func application(_ application: UIApplication,
                 didReceiveRemoteNotification userInfo: [AnyHashable : Any],
                 fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    

    self.flutterMethodChannelLocalNotification.invokeMethod("localnotification", arguments: userInfo["data"] ?? "")// output: "some-value"
    let data = userInfo["data"] as? [String:Any]
    let param : [String:Any] = [KeyCenter.kUserId: data?[KeyCenter.kNotificationForUserId] ?? "" ,
                                KeyCenter.kGroupId: data?[KeyCenter.kGroupId] ?? "",
                                KeyCenter.kChatType: data?[KeyCenter.kChatType] ?? ""]
    print("Param data = \(param)")
    viewModel = ViewModel()
    viewModel.doubleTickCallApi(params: param, completion:{ (sucsses, message) in
        if sucsses{

        }else{
            print(message ?? "Unexpected")
        }
        completionHandler(.newData)
    })
    // Inform the system after the background operation is completed.
}

写入param时写的功能,它将是param data = [“ userId”:“”,“”,“ chattype”:“ “,” groupId“:”]。如何处理可选的userInfo [“ data”]在这里值?

I am implementing notification in flutter app and checking for iOS. Scenario is when user receive notification in iOS I want to encrypt that data to use for further feature implementation. Here is my function which I write in AppDelegate file

override func application(_ application: UIApplication,
                 didReceiveRemoteNotification userInfo: [AnyHashable : Any],
                 fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    

    self.flutterMethodChannelLocalNotification.invokeMethod("localnotification", arguments: userInfo["data"] ?? "")// output: "some-value"
    let data = userInfo["data"] as? [String:Any]
    let param : [String:Any] = [KeyCenter.kUserId: data?[KeyCenter.kNotificationForUserId] ?? "" ,
                                KeyCenter.kGroupId: data?[KeyCenter.kGroupId] ?? "",
                                KeyCenter.kChatType: data?[KeyCenter.kChatType] ?? ""]
    print("Param data = \(param)")
    viewModel = ViewModel()
    viewModel.doubleTickCallApi(params: param, completion:{ (sucsses, message) in
        if sucsses{

        }else{
            print(message ?? "Unexpected")
        }
        completionHandler(.newData)
    })
    // Inform the system after the background operation is completed.
}

when I print param it will be Param data = ["userId": "", "chatType": "", "groupId": ""]. How to handle optional userInfo["data"] value here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无法言说的痛 2025-02-07 07:27:19

解决方案是我必须在JSON中解析通知数据,然后使用它

let data = userInfo[AnyHashable("data")] as? String
let jsonData = data?.data(using: .utf8)!
let json = try! JSONSerialization.jsonObject(with: jsonData!, options: .allowFragments) as! NSDictionary

 let param : [String:Any] = [KeyCenter.kUserId: json[KeyCenter.kNotificationForUserId] ?? "" ,
                                    KeyCenter.kGroupId: json[KeyCenter.kGroupId] ?? "",
                                    KeyCenter.kChatType: json[KeyCenter.kChatType] ?? ""]

Solution is I have to parse notification data in json and then use it

let data = userInfo[AnyHashable("data")] as? String
let jsonData = data?.data(using: .utf8)!
let json = try! JSONSerialization.jsonObject(with: jsonData!, options: .allowFragments) as! NSDictionary

 let param : [String:Any] = [KeyCenter.kUserId: json[KeyCenter.kNotificationForUserId] ?? "" ,
                                    KeyCenter.kGroupId: json[KeyCenter.kGroupId] ?? "",
                                    KeyCenter.kChatType: json[KeyCenter.kChatType] ?? ""]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文