【问题标题】:Found incompatible Titanium Modules for GCM Integration发现用于 GCM 集成的不兼容 Titanium 模块
【发布时间】:2017-08-31 10:03:56
【问题描述】:
我正在尝试将GCM 集成到钛应用加速器中。
我在我的钛项目中集成了 net.iamyellow.gcmjs 模块。但出现以下错误。
[错误]:发现不兼容的钛模块:[错误]:id:
net.iamyellow.gcmjs 版本:0.2 平台:android min sdk:
3.0.2.GA
而我的titanium SDK 版本是6.1.2.GA。
【问题讨论】:
标签:
android
google-cloud-messaging
titanium
appcelerator-titanium
【解决方案1】:
为了帮助您入门,here are some good guidelines。此外,您会找到可以帮助您或至少让您了解代码有什么问题以及为什么会出现该错误的代码示例。您可以从网站提供的代码中比较您的代码。
让我们从几行配置开始。打开 tiapp.xml 文件
您的 Titanium 项目,因为我们需要先声明模块。
完成后,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();
只需浏览该网站以了解更多技巧。
希望这会有所帮助。