2012-01-22 55 views
0

我正在使用Appcelerator开发iOS应用程序。在这个应用程序中,我想使用推送通知。 在我的app.js中,我添加了下面的代码,但是当我在手机上运行它时,它甚至没有注册该应用程序想要使用推送。无法在Appcelerator上注册推送通知

我正在使用Titanium的SDK 1.8。奇怪的是,我的其他应用程序上的较低SDK上的代码完全相同,代码为 。

// 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(); 

} 

回答

0

首先,确保你已经安装在tiapp.xml

第二模块:您需要填写

var APP_KEY = 'XXXXX'; 

var APP_SECRET = 'XXXXX'; 

你APP_KEY和app_secret可以在顶部找到你tiapp.xml文件(源代码,不是GUI)

Cheers