OneSignal-Swift-接收不同语言的推送通知

问题描述 投票:0回答:1

我正在使用OneSignal的SDK。假设,我有以下用例:

用户A以德语使用我的应用程序。他在应用程序e中触发动作。 G。用户B的图片上显示“赞”。用户B收到有关赞的推送通知。但是用户B使用英语的应用程序。我该如何实现?

[我的意思是,我可以用特定语言发送通知消息,但是如果用户B决定将移动设备的语言更改为土耳其语,那么我必须保持灵活。

有什么办法,我可以在目标设备上访问传入的推送通知?

当前,我用于从源设备发送通知的代码如下:

 public func notifyAboutSubscription(userObject:User, receiverArray:[String]) {
       var receiverArray = removeChallengeCreatorTokenFromArray(receiverArray: receiverArray)
        notificationTypeService.clearReceiverListForNotificationType(completionHandler: { (clearedReceiverArray) in
            receiverArray = clearedReceiverArray

            let source = self.determineUserType(userObject: userObject)
            // actual message is source + FOLLOW_MESSAGE
            OneSignal.postNotification(["contents": ["en": source
                + FOLLOW_MESSAGE], "include_player_ids": receiverArray])
        }, receiverList: receiverArray, notificationType: NotificationType.follow)
    }
swift xcode push-notification onesignal nslocalizedstring
1个回答
0
投票

好的。我刚刚找到解决方案。这是上面的修改后的代码:

public func notifyAboutSubscription(userObject:User, receiverArray:[String]) {
    var receiverArray = removeChallengeCreatorTokenFromArray(receiverArray: receiverArray)


    notificationTypeService.clearReceiverListForNotificationType(completionHandler: { (clearedReceiverArray) in
        receiverArray = clearedReceiverArray

        let source = self.determineUserType(userObject: userObject)
        OneSignal.postNotification(["contents": ["en": source +
            " started following you", "de": source + " folgt dir jetzt", "tr": source + " seni takip ediyor"], "include_player_ids": receiverArray])
    }, receiverList: receiverArray, notificationType: NotificationType.follow)
}

您基本上为每种语言添加了相应的键。根据设备语言,显示正确的消息。

© www.soinside.com 2019 - 2024. All rights reserved.