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

问题描述

我创建了一个简单的iOS本机应用程序,除了OneSignal初始化代码外,什么都没有.我在两个设备(设备A和设备B)上安装了我的应用程序.这两个设备都订阅了OneSignal应用程序控制台.当我从OneSignal Web控制台发送通知时,这两个设备都可以接收该通知.

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-send-notifications

I followed the OneSignal iOS SDK document and created the following functionhttps://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?

我什至从此讨论中复制并运行此没有任何问题的代码" /a>,但仍显示相同的授权错误.我在做什么错了?

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 12:23