如何修复推送通知标题未迅速显示正确的字符串

时间:2019-07-23 13:08:41

标签: swift push-notification firebase-notifications

我的应用程序中显示的FCM推送通知遇到了一些问题。 这是FCM发送给我的数据:

["roomId": 253539,
"type": ROOM_SEND_MESSAGE,
"aps": {
    alert = {
        "loc-args" = (
            "TEST STRING"
        );
        "loc-key" = "CHANNEL_MESSAGE_IMAGE";
    };
    "content-available" = 1;
    sound = default;
},"messageId": 15638864319517014,
"gcm.message_id": 1563886435277772]

这是问题所在: 每当我收到通知时,它应该向我显示“ loc-args”中的参数,但会向我显示“ loc-key”中的值 检查下面的图像 the image for my problem 这是我的appDelegate中的代码

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    if SMLangUtil.loadLanguage() == "fa" {
        IGGlobal.languageFileName = "localizationsFa"
    } else {
        IGGlobal.languageFileName = "localizationsEn"
    }
    let stringPath : String! = Bundle.main.path(forResource: IGGlobal.languageFileName, ofType: "json")
    MCLocalization.load(fromJSONFile: stringPath, defaultLanguage: SMLangUtil.loadLanguage())
    MCLocalization.sharedInstance().language = SMLangUtil.loadLanguage()

    if SMLangUtil.loadLanguage() == "fa" {
        UITableView.appearance().semanticContentAttribute = .forceRightToLeft
    } else {
        UITableView.appearance().semanticContentAttribute = .forceLeftToRight
    }

    SMUserManager.clearKeychainOnFirstRun()
    SMUserManager.loadFromKeychain()
    realmConfig()
    Fabric.with([Crashlytics.self])
    _ = IGDatabaseManager.shared
    _ = IGWebSocketManager.sharedManager
    _ = IGFactory.shared
    _ = IGCallEventListener.sharedManager // detect cellular call state

    UITabBar.appearance().tintColor = UIColor.white

    let tabBarItemApperance = UITabBarItem.appearance()
    tabBarItemApperance.setTitleTextAttributes(convertToOptionalNSAttributedStringKeyDictionary([convertFromNSAttributedStringKey(NSAttributedString.Key.foregroundColor):UIColor.red]), for: UIControl.State.normal)
    tabBarItemApperance.setTitleTextAttributes(convertToOptionalNSAttributedStringKeyDictionary([convertFromNSAttributedStringKey(NSAttributedString.Key.foregroundColor):UIColor.white]), for: UIControl.State.selected)

    UserDefaults.standard.setValue(false, forKey:"_UIConstraintBasedLayoutLogUnsatisfiable")

    pushNotification(application)
    detectBackground()
    IGGlobal.checkRealmFileSize()
    return true
}
  /******************* Notificaton Start *******************/

    func pushNotification(_ application: UIApplication){
        FirebaseApp.configure()
        Messaging.messaging().isAutoInitEnabled = true
        Messaging.messaging().delegate = self
        Messaging.messaging().shouldEstablishDirectChannel = true

        if #available(iOS 10.0, *) { // For iOS 10 display notification (sent via APNS)
            /**
             * execute following code in "IGRecentsTableViewController" and don't execute here,
             * for avoid from show permission alert in start of app when user not registered yet
             **/
            //UNUserNotificationCenter.current().delegate = self
            //let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound, .carPlay]
            //UNUserNotificationCenter.current().requestAuthorization(options: authOptions,completionHandler: {_, _ in })
        } else {
            let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
            application.registerUserNotificationSettings(settings)
        }

        application.registerForRemoteNotifications()
        self.voipRegistration()

    }

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        voipRegistration()
    }
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {

        print("||||||NOTIFICATION||||||||")
        print(userInfo)

        if let roomId = userInfo["roomId"] as? String {
            let unreadCount = IGRoom.updateUnreadCount(roomId: Int64(roomId)!)
            application.applicationIconBadgeNumber = unreadCount
        }
    }
    /******************* Notificaton End *******************/

1 个答案:

答案 0 :(得分:0)

对于任何面临相同或相似问题的人,我找到了问题的答案:D

因为所有通知都由操作系统处理,所以我要做的就是更深入地发现问题 我要做的就是重新创建可本地化的文件,然后 boom 一切按顺序进行:)