OneSignal iOS SDK 发送通知失败代码 400 [英] OneSignal iOS SDK send notification fail Code 400

查看:31
本文介绍了OneSignal iOS SDK 发送通知失败代码 400的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的 iOS 本机应用程序,它只有 OneSignal 初始化代码.我在我的两台设备上安装了我的应用程序,设备 A 和设备 B.两台设备都订阅了我的 OneSignal 应用程序控制台.当我从 OneSignal Web Console 发送通知时,两台设备都可以收到通知.

I have created a simple iOS native App which has nothing but OneSignal initializaion codes. I installed my App on my 2 devices, device A and device B. Both devices are subscribed to my OneSignal App Console. When I send a notification from OneSignal Web Console, the 2 devices can both recive the notification.

当我点击设备 A 上的按钮时,设备 A 会向设备 B 发送通知.

When I click on a button on device A, device A will send a notification to device B.

我按照 OneSignal iOS SDK 文档创建了以下函数https://documentation.onesignal.com/docs/ios-native-sdk#section-sending-notifications

I followed the OneSignal iOS SDK document and created the following function https://documentation.onesignal.com/docs/ios-native-sdk#section-sending-notifications

func onButtonClick() {
    OneSignal.postNotification(
        [
            "contents": ["en": "Test Message"],
            "include_player_ids": ["c00bb8a6-79da-419b-9999-e919831a5223"] // id of device B
        ],
        onSuccess: {(result) in print("success") },
        onFailure: {(error) in print("error : \(error)") }
    )
}

但是,当我单击按钮时,xCode 调试控制台中会显示错误:

however, when I clicked the button, an error shows up in the xCode debug console:

2017-01-20 11:15:52.702852 my.bundle.id[2263:1201122] ERROR: Create notification failed
error : Optional(Error Domain=OneSignalError Code=400 "(null)" UserInfo={returned={
    errors =     (
        "Please include a case-sensitive header of Authorization: Basic <YOUR-REST-API-KEY-HERE> with a valid REST API key."
    );
    reference =     (
        "https://documentation.onesignal.com/docs/accounts-and-keys#section-keys-ids"
    );
}})

我很困惑,因为根据 OneSignal 参考文档,发送带有include_player_ids"的通知不需要 API 身份验证密钥.

I was confused, because according to the OneSignal Reference document, send notification with "include_player_ids" Does not require API Auth Key.

https://documentation.onesignal.com/reference#create-notification

它还说:切勿在客户端代码中使用您的REST API 密钥",它仅适用于您的系统或服务器.

那么这个错误是什么意思?我该怎么办?

So what does this error mean? And what should I do?

我什至从这个讨论中复制并运行了这个没有任何问题的工作"代码,但仍然出现相同的授权错误.我做错了什么?

I even copied and run this "work without any problems" code from this discussion, but the same Authorization error still shows up. What am I doing wrong?

推荐答案

答案

升级SDK,问题就解决了.

The Answer

Just upgrade the SDK and the problem will be gone.

这是 OneSignal-iOS-SDK 2.3.1 中的一个错误,此错误已在 2.3.2 中修复.

This was a bug in OneSignal-iOS-SDK 2.3.1, this bug was fixed in 2.3.2.

请参阅他们的 Github 发行说明.

Please see their Github Release Notes.

始终在 pod install 之前运行 pod repo update 以确保 pod 安装最新版本的框架.

Always run pod repo update before pod install to ensure that the pod install the latest version of the frameworks.

感谢 One Signal Conversations 的 Kevin、Jason 和 Josh 帮助我解决了这个问题.

Thanks Kevin, Jason and Josh from One Signal Conversations to help me solve this problem.

这篇关于OneSignal iOS SDK 发送通知失败代码 400的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆