如何解决:语言内容在Swift中与OneSignal抱怨

Dav*_*eek 6 ios swift onesignal

我正在使用OneSignal来管理我的推送通知.对于某些通知,我收到:

通知必须包含英语内容

但我只是用英语发送一切......

oneSignal.postNotification(["headings" : ["en": "\(who)"],
                            "subtitle" : ["en": "\(subtitle)"],
                            "contents" : ["en": "\(contents)"],
                            "include_player_ids": [result]],
Run Code Online (Sandbox Code Playgroud)

谁,副标题,内容是字符串,结果是接收者ID.大多数通知都是发送的,对于一些我收到错误消息.

安慰:

> ERROR: Create notification failed
Error Domain=OneSignalError Code=400 "(null)" UserInfo={returned={
    errors =     (
        "  Notifications must have English language content"
    );
}}
Run Code Online (Sandbox Code Playgroud)

我的完整功能:

func sendPush(_ receiverID: String, _ who: String, _ didWhat: String, _ message: String?) {

    var subtitle = ""
    var contents = ""
    if message != nil {
        contents = message!
    }

    switch didWhat {
    case "likePost":
        subtitle = "liked your post"
    case "commentPost":
        subtitle = "commented on your post"
    case "likeComment":
        subtitle = "liked your comment"
    case "message":
        subtitle = "sent you a message"
    case "friendsRequest":
        subtitle = "sent you a friend request"
    case "friendAccept":
        subtitle = "accepted your friend request"
    case "follow":
        subtitle = "just followed you"
    default:
        break
    }

    getOneSignalPlayerID(receiverID, completion: { result in

        oneSignal.postNotification(["headings" : ["en": "\(who)"],
                                    "subtitle" : ["en": "\(subtitle)"],
                                    "contents" : ["en": "\(contents)"],
                                    "include_player_ids": [result]],
        onSuccess: { (success) in
            if success != nil {
                print(success!)
            }
        }, onFailure: { (failure) in
            if failure != nil {
                print(failure!)
                crashlyticsLog("getOneSignalPlayerID", failure!.localizedDescription)
            }
        })
    })
}
Run Code Online (Sandbox Code Playgroud)

我错过了什么?非常感谢帮助.

Vin*_*ent 6

我认为 4 个字段之一是错误的。在这种情况下,错误可能意味着它包含非法字符或非英文编码中的字符。在发布通知之前打印每个字段。

引发此错误的另一种情况可能是因为其中一个字段为空或为零。在发布通知之前再次将它们打印到日志中。

  • 我会。我也会奖励你的赏金。赏金只剩下 6 天了,也许有人有有用的提示或类似的东西。别担心。不会忘记你。 (3认同)