首页 > 解决方案 > 如何在通知中显示阿拉伯语文本?

问题描述

我收到英语/阿拉伯语两种语言的 FCM 推送通知,但我只想用阿拉伯语显示,如何显示?

我的代码-

@available(iOS 10, *)
extension AppDelegate : 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
        if let jsonResult = userInfo as? Dictionary<String, AnyObject> {

            if let notifyType = jsonResult["type"] as? String {

                if notifyType == "8" ||  notifyType == "18" {
                    self.pushRedirection(userInfo: userInfo)

                }else{

                    if let league_id = jsonResult["league_id"] as? String {

                        if let contestUnique_id = jsonResult["contest_unique_id"] as? String {

                        }
                    }
                }                    
            }
        }        
        completionHandler([.alert,.sound])
}

我收到了英文通知(比赛提醒)。如何用阿拉伯语设置

在此处输入图像描述

我的通知数据是 -

[AnyHashable("gcm.notification.type"): 5, AnyHashable("league_id"): 3, AnyHashable("en_msg"): Match Reminder, AnyHashable("gcm.notification.ar_msg"): القوانين, AnyHashable("gcm.notification.en_msg"): Match Reminder, AnyHashable("gcm.notification.league_id"): 3, AnyHashable("contest_unique_id"): KBm8oVuTR, AnyHashable("gcm.message_id"): 0:1528974245362555%6c5fd9d06c5fd9d0, AnyHashable("gcm.notification.contest_unique_id"): KBm8oVuTR, AnyHashable("ar_msg"): القوانين, AnyHashable("google.c.a.e"): 1, AnyHashable("type"): 5, AnyHashable("aps"): {
    alert = "Match Reminder";
}, AnyHashable("body"): Match Reminder]

标签: swiftswift3push-notification

解决方案


您需要编写一个通知服务扩展。这将允许您在显示之前修改通知的有效负载。

正如文档所说:

UNNotificationServiceExtension 对象...允许您在将远程通知传递给用户之前对其内容进行自定义。

这正是你想要做的。


推荐阅读