0
我正在尝试将GCM
集成到钛加速器中。找到用于GCM集成的不兼容钛模块
我在我的钛项目中整合了net.iamyellow.gcmjs模块。但得到以下错误。
[错误]:发现不兼容的钛模块:[错误]:ID: net.iamyellow.gcmjs版本:0.2平台:Android的SDK分钟: 3.0.2.GA
和我titanium SDK
版本是6.1.2.GA
。
我正在尝试将GCM
集成到钛加速器中。找到用于GCM集成的不兼容钛模块
我在我的钛项目中整合了net.iamyellow.gcmjs模块。但得到以下错误。
[错误]:发现不兼容的钛模块:[错误]:ID: net.iamyellow.gcmjs版本:0.2平台:Android的SDK分钟: 3.0.2.GA
和我titanium SDK
版本是6.1.2.GA
。
为了帮助您入门,here are some good guidelines。另外,你会找到一些代码示例,它们会帮助你,或者至少让你知道你的代码有什么问题,以及它为什么会给你那个错误。您可以比较网站提供的代码中的代码。
让我们从几行配置开始。打开Titanium项目的tiapp.xml文件 ,因为我们需要首先声明模块。 完成后,gcm.js只需要一个属性即可使事情发挥作用:发件人ID为 。正如你在下面的例子中看到的,只是与信息填入属性 值:
<property name="GCM_sender_id" type="string">YOUR_SENDER_ID</property>
<modules>
<module platform="android" version="0.2">net.iamyellow.gcmjs</module>
</modules>
现在,在某处你的应用中,您需要注册它推 通知:
var gcm = require('net.iamyellow.gcmjs')
var pendingData = gcm.data;
if (pendingData && pendingData !== null) {
// if we're here is because user has clicked on the notification
// and we set extras for the intent
// and the app WAS NOT running
// (don't worry, we'll see more of this later)
Ti.API.info('******* data (started) ' + JSON.stringify(pendingData));
}
gcm.registerForPushNotifications({
success: function (ev) {
// on successful registration
Ti.API.info('******* success, ' + ev.deviceToken);
},
error: function (ev) {
// when an error occurs
Ti.API.info('******* error, ' + ev.error);
},
callback: function() {
// when a gcm notification is received WHEN the app IS IN FOREGROUND
alert('hellow yellow!');
},
unregister: function (ev) {
// on unregister
Ti.API.info('******* unregister, ' + ev.deviceToken);
},
data: function (data) {
// if we're here is because user has clicked on the notification
// and we set extras in the intent
// and the app WAS RUNNING (=> RESUMED)
// (again don't worry, we'll see more of this later)
Ti.API.info('******* data (resumed) ' + JSON.stringify(data));
}
});
// in order to unregister:
// require('net.iamyellow.gcmjs').unregister();
只是探索网站有一个扩大视图的技巧。
希望这会有所帮助。