Push notification 无法在Appcelerator上注册推送通知
我正在使用Appcelerator开发一个iOS应用程序。在这个应用中,我想使用推送通知。 在我的app.js中,我添加了以下代码,但当我在手机上运行它时,它甚至没有注册应用程序想要使用推送 我使用的是钛合金SDK 1.8。奇怪的是,完全相同的代码工作 在我的其他应用程序中,较低的SDK很好Push notification 无法在Appcelerator上注册推送通知,push-notification,appcelerator,urbanairship.com,Push Notification,Appcelerator,Urbanairship.com,我正在使用Appcelerator开发一个iOS应用程序。在这个应用中,我想使用推送通知。 在我的app.js中,我添加了以下代码,但当我在手机上运行它时,它甚至没有注册应用程序想要使用推送 我使用的是钛合金SDK 1.8。奇怪的是,完全相同的代码工作 在我的其他应用程序中,较低的SDK很好 // Set the Urban Airship credentials var APP_KEY = 'XXXXX'; // Set the Urban Airship credentials var
// Set the Urban Airship credentials
var APP_KEY = 'XXXXX';
// Set the Urban Airship credentials
var APP_SECRET = 'XXXXX';
// Start the register function
Titanium.Network.registerForPushNotifications({
// Set the push types
types:[
Titanium.Network.NOTIFICATION_TYPE_BADGE,
Titanium.Network.NOTIFICATION_TYPE_ALERT,
Titanium.Network.NOTIFICATION_TYPE_SOUND
],
// If the call was successful
success: successCallback,
// If the call resulted in an error
error: errorCallback,
// The message callback
callback: messageCallback
});
function successCallback(e) {
// Setup the XHR client
var request = Titanium.Network.createHTTPClient({
// Setup the onload
onload:function(e) {
if (request.status != 200 && request.status != 201) {
// Set the response
request.onerror(e);
// Return
return;
}
},
// Set up the error
onerror:function(e) {
Ti.API.info("Register with Urban Airship Push Service failed. Error: "+ e.error);
}
});
// Set the device token
Titanium.App.Properties.setString("device_token", e.deviceToken);
// Register device token with UA
request.open('PUT', 'https://go.urbanairship.com/api/device_tokens/'+ e.deviceToken, true);
// Set the basic authentication
request.setRequestHeader('Authorization','Basic ' + Titanium.Utils.base64encode(APP_KEY + ':' + APP_SECRET));
// Send the request
request.send();
}
首先,确保已将模块安装在tiapp.xml中 第二:你需要填写
var APP_KEY = 'XXXXX';
var APP_SECRET = 'XXXXX';
您的app_密钥和app_机密可以在tiapp.xml文件的顶部找到,该文件是源代码,而不是GUI
干杯