【问题标题】:Sending Parse Push Notification via website通过网站发送解析推送通知
【发布时间】:2015-09-18 23:25:31
【问题描述】:

多年来,我一直在使用 Parse 向我的 iOS 应用程序发送推送通知,它运行良好。

我现在希望能够做同样的事情 - 但来自我自己的网页。意思是,我只想转到一个常规网页(我将创建它),在文本字段中输入一些文本,按下一个按钮 - 然后将该文本作为推送通知发送到我的 iOS 应用程序。

我已经尝试了以下代码 - 到目前为止没有运气:

<html>
<head>
<title>PN TEST</title>

<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript" src="http://www.parsecdn.com/js/parse-1.2.0.min.js"></script>

<script type="text/javascript">

Parse.initialize("xxxxxxxxxxxxx", "xxxxxxxxxxxxxxx");

function makePushNotification() {
    alert ('sending a push!');

    $.ajax({
           type: 'POST',
           headers: { 'X-Parse-Application-Id’ : ‘xxxxxxxxxxxxxxxxxxxxxxxx’ , 'X-Parse-REST-API-Key’ : ‘xxxxxxxxxxxxxxxxxxxxxxxxxxx' },
           url: "https://api.parse.com/1/push", data: '{"channel": "",   "data": {"alert": "Sending a Push Notification from my web page."} }',
            contentType: "application/json"
        }); 
}


</script>

</head>


<body>
    Enter your push notification: <br/>

    <form id="testForm">
        <textarea cols="60" rows="4" id="textAreaText"></textarea>
            <br/>
        <input type="button" value="Send Push Notification" onclick="makePushNotification()" />
            <br/>
    </form>

</body>
</html>

(显然我在这里硬编码推送通知的实际文本,而不是真正从textarea 框中读取它 - 但这只是现在。)

无论如何,有什么想法缺少什么吗?

【问题讨论】:

    标签: ios parse-platform push-notification


    【解决方案1】:

    contentType: "application/json" 应该是一个标头。

    'Content-Type': 'application/json'
    

    【讨论】:

    • 你的意思是它应该放在上面的 JSON 的headers 部分?在这里的意思:headers: { 'X-Parse-Application-Id’ : ‘xxxxxxxxxxxxx...` ?
    • 我按照你的建议做了,得到了这个错误:[Error] Failed to load resource: Request header field contentType is not allowed by Access-Control-Allow-Headers. (push, line 0)
    • @Sirab33 它应该是“内容类型”,就像我在回答中所说的那样。
    猜你喜欢
    • 2017-10-29
    • 1970-01-01
    • 2017-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多