- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
$messag-6ren">
要从服务器向 android 应用程序发送推送通知,我使用以下脚本。
<?php
$message = "hi there";
$apiKey = "xxxxxxxxxxxx";
$registrationIDs = array("xxxxxxx");
$url = 'https://android.googleapis.com/gcm/send';
// Set POST variables
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array( "message" => $message,
)
);
$headers = array(
'Authorization: key=' . $apiKey,
'Content-Type: application/json'
);
$ch = curl_init(); // Open connection
curl_setopt($ch, CURLOPT_URL, $url );
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $fields ));
$result = curl_exec($ch); // Execute post
if($result === false)
die('Curl failed ' . curl_error());
curl_close($ch);
//return $result;
// curl_close($ch); // Close connection
$response = json_decode($result);
print_r($response);
?>
此代码适用于 native android 应用程序,但是当我使用上述脚本发送推送通知时,使用钛开发的应用程序,设备收到通知,但带有“NULL”payload
。
我想知道,为什么?我的 PHP 脚本有什么问题。
更新
这是我接收通知的代码
// These events monitor incoming push notifications
CloudPush.addEventListener('callback', function (evt) {
//Ti.API.info('This is the payload data i got'+JSON.parse(evt.payload));
Ti.API.log("This is the GCM response "+JSON.stringify(evt));
alert(evt.payload);
//var payload = JSON.parse(evt.payload);
//Ti.API.info('This is the message data i got'+payload.message);
});
CloudPush.addEventListener('trayClickLaunchedApp', function (evt) {
Ti.API.info('Tray Click Launched App (app was not running)');
});
CloudPush.addEventListener('trayClickFocusedApp', function (evt) {
Ti.API.info('Tray Click Focused App (app was already running)');
});
这是回应
[INFO] : APSCloudPush: receivePayload: null
[INFO] : APSCloudPush: background: true
[INFO] : APSCloudPush: queuePayload: null
[INFO] : APSCloudPush: showTrayNotification
[ERROR] : APSCloudPush: Payload is null!
最佳答案
上面给出的代码是绝对正确的。我想问题只是关键字有效负载。只需将服务器端脚本中的“消息”一词替换为“有效负载”,如下所示。
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array( "payload" => $message,
)
);
因为在 Titanium ti.cloudePush
模块内部搜索单词 payload
关于php - 使用 PHP 向钛(跨平台)开发的 android 应用程序发送推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30182543/
我正在开发一组应用程序,它们协同工作以创建一个用于处理计量数据的系统。我想让它们松散耦合有几个原因,并且系统应该可以由第三方扩展,因此应用程序将通过消息传递绑定(bind)在一起。 我正在寻找一种消息
如果我使用 python 2.6 和 Qt 为 windows 创建一个 gui,然后想在 solaris 或 linux 世界中运行。 我在两个系统上都需要什么,我猜两个平台都需要 2.6 和 Qt
我正在运行 Linux Ubuntu 10.04,我有一台 Windows 7 机器和一台运行 Mac OS X 10.6.4 的 MacBook。我如何编写一个简单的 C 程序(如 不是 QT!),
前言 今天给大家分享一个.NET开源(MIT License)、免费、跨平台(适用于 Windows、MacOS 和 Linux )、使用简单的面部识别库:FaceRecognitionDotNet
我知道汇编语言通常不是跨平台的。即使使用像 NASM 这样的东西,对于不同的架构和平台,您仍然需要不同的代码,这些架构和平台具有不同的运行时和诸如中断之类的东西的实现。但是如果有人因为喜欢汇编语言而想
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 8年前关闭。 Improve thi
This question already has answers here: How to play audio? (20个答案) 12天前关闭。 我正在编写一个dhtml应用程序,该应用程序创建系
我正在使用MonoGame开发一款游戏,该游戏使用SoundEffectInstance来实现游戏中的音效。在可以创建的SoundEffect实例数量以及可以同时播放的最重要实例方面,不同平台受到什么
如何在 java 中找到并运行默认计算器而不使我的程序依赖于平台。我可以对每个主要操作系统的所有路径进行硬编码,然后找到该人正在使用的操作系统,然后使用该操作系统各自的路径。但是,我不想那样做,有没有
有没有办法使用捏合来放大共享的Xamarin Forms,我只找到了每个平台的实现。 最佳答案 您可以使用 Pan Gesture 来实现它。这里有一个很好的在 PanContainer 中包装图像的
是否有最好/好的方法来同时为 Android 和 iOS(以及 Mac OS X)开发跨平台应用程序,例如游戏? 只是简单地开发一个仅使用 OpenGL 和 C/C++ 的应用程序应该很简单,不是吗?
我想知道 CSS 行为是否会随着操作系统的不同而变化。我的 css 对于 vista 和 win xp proffesional 对于相同版本的浏览器来说有点不同。我在 vista + ie8 和 x
我需要一种跨平台的方式来检查给定的文件路径是否是绝对的而不使用Pathname 库。为此,我唯一希望依赖的库是 File。它需要跨平台和跨实现,因此无论是 Ruby MRI、JRuby、Rubiniu
我正在尝试寻找一种跨平台的方法来从文件末尾删除 X 字节。 目前我发现: 特定于平台的解决方案(例如 truncate for posix):这是我不想要的,因为我希望 C++ 程序可以在多个平台上运
我想将可执行文件从一个目录复制到另一个目录。 源目录包括各种我不关心的文件(构建工件)。我只想使用适用于 OS X 和 Linux 的 bash 脚本获取可执行文件。 可执行文件是指具有可执行权限的文
我需要能够在服务器端处理简单 HTTP GET/PUT 请求的库。有一些特殊要求: 应该是跨平台的(这是主要因素) 支持多线程。 高性能 支持 HTTPS 许可证应允许链接专有代码(LGPL、BSD)
我正在寻找一种可用于从 Windows 和 Mac OSX 计算机上传大型 (~2GB) 文件的技术。应该可以根据请求/错误暂停和恢复上传。具有基本计算机技能的用户应该可以轻松安装最终产品。 我正在考
我正在寻找一种使用 java 播放 .flv 文件的方法。这意味着我需要一个跨平台的 ffmpeg 库。我一直在玩弄 jmf 和 fobs4jmf,但我无法在 linux 中播放,因为我需要一个本地库
我想在基于浏览器的应用程序中做的一件事是允许用户选择一些文本(不是在 中,只是普通的文本!),然后让我的应用程序弹出一个然后可以与下一个交互的小工具栏(在我的例子中,添加注释)。 我在 google
对于 PyInstaller 中的新功能,我们需要一个命令行选项来接收其中包含任何分隔符的字符串。这是讨论:https://github.com/pyinstaller/pyinstaller/pul
我是一名优秀的程序员,十分优秀!