2016-07-04 62 views
0

我nedd为我的应用程序创建推送通知,适用于Android和IOS。 我已阅读文档,但无法弄清楚如何使这个工作。钛推推式通知

让某人成为一个可以展示给我的exmaple代码,以便我可以看到它是如何工作的? 我试过这个IOS:

var deviceToken;

Titanium.Network.registerForPushNotifications({ 
    success : function(e) { 
     deviceToken = e.deviceToken; 
     alert("deviceToken = " + deviceToken); 
     //subscribeToChannel(); 
    }, 
    error : function(e) { 
     alert("Error: " + e.message); 
    }, 
    callback : function(e) { 
     alert("deviceToken = " + deviceToken); 
     //recebePush(e.data); 
    } 
}); 

但成功,错误公关回调函数AR从来没有发射。

在Android中我尝试这样做:

// Require the module 
var CloudPush = require('ti.cloudpush'); 
var deviceToken = null; 

// Initialize the module 
CloudPush.retrieveDeviceToken({ 
    success: deviceTokenSuccess, 
    error: deviceTokenError 
}); 
// Enable push notifications for this device 
// Save the device token for subsequent API calls 
function deviceTokenSuccess(e) { 
    deviceToken = e.deviceToken; 
} 
function deviceTokenError(e) { 
    alert('Failed to register for push notifications! ' + e.error); 
} 

// Process incoming push notifications 
CloudPush.addEventListener('callback', function (evt) { 
    alert("Notification received: " + evt.payload); 
}); 

但它总是会返回一个错误说:“无法为推送通知注册INVALID_SENDER

我已经生成的GCM API密钥和GCM发送者ID!为Android创建了IOS的证书,但它没有工作

回答

0

您可以找到完整的分步指南来配置推送通知服务from here

,你可以得到为获得设备令牌完整的指南,并与例如推送通知订阅设备From Here

+0

我已经更新了我的问题,如果你可以看看 –

0

您注册GCM API密钥/发件人ID和与Appcelerator的平台,您的APNS证书(在菜单应用下> YOURAPP>箭头>推送通知)。

您需要将这些凭证注册到Appcelerator,并且您需要在Appcelerator Studio中为您的应用启用Appcelerator Platform Services。你应该在你的tiapp.xml中看到类似这样的东西:

<property name="acs-authbase-url" type="string">https://secure-identity.cloud.appcelerator.com</property> 
<property name="acs-base-url" type="string">https://api.cloud.appcelerator.com</property> 
<property name="acs-push-api-url" type="string">https://api.cloud.appcelerator.com/v1/</property> 
<property name="acs-api-key-production" type="string">xxxxxxxxxxxxxx</property> 
<property name="acs-api-key-development" type="string">xxxxxxxxxxxxxx</property>