2012-11-12 94 views
2

您好我正在使用ACS在我的應用程序中實現推送通知。我在tiapp.xml中添加了Ti.cloud推送,如下所示。Ti.cloudpush模塊未找到

<module platform="android">ti.cloudpush</module> 

我使用這段代碼實現它,但它給錯誤,Ti.cloudpush模塊找不到。

var HomeWin = Titanium.UI.createWindow({ 
    backgroundColor : '#f00' 
}); 
var CloudPush = require('ti.cloudpush'); 
CloudPush.debug = true; 
CloudPush.enabled = true; 
CloudPush.showTrayNotificationsWhenFocused = true; 
CloudPush.focusAppOnPush = false; 

var deviceToken; 

var Cloud = require('ti.cloud'); 
Cloud.debug = true; 


var submit = Ti.UI.createButton({ 
    title : 'Register For Push Notification', 
    color:'#000', 
    height : 53, 
    width : 200, 
    top : 100, 
}); 

HomeWin.add(submit); 

submit.addEventListener('click', function(e) { 
    CloudPush.retrieveDeviceToken({ 
     success: function deviceTokenSuccess(e) { 
        alert('Device Token: ' + e.deviceToken); 
        deviceToken = e.deviceToken 
        loginDefault(); 
       }, 
     error : function deviceTokenError(e) { 
        alert('Failed to register for push! ' + e.error); 
      } 
    }); 
}); 


function loginDefault(e){ 
    //Create a Default User in Cloud Console, and login 
    Cloud.Users.login({ 
     login: 'push123', 
     password: 'push123' 
    }, function (e) { 
     if (e.success) { 
      alert("login success"); 
      defaultSubscribe(); 
     } else { 
       alert('Error: ' +((e.error && e.message) || JSON.stringify(e))); 
     } 
    }); 
} 

function defaultSubscribe(){ 
    Cloud.PushNotifications.subscribe({ 
      channel: 'alert', 
      device_token: deviceToken, 
      type: 'android' 
    }, function (e){ 
      if (e.success) { 
       alert('Subscribed for Push Notification!'); 
      } else{ 
       alert('Error:' +((e.error && e.message) || JSON.stringify(e))); 
      } 
    }); 
} 

CloudPush.addEventListener('callback', function (evt) { 
    alert(evt); 
    alert(evt.payload); 
}); 

CloudPush.addEventListener('trayClickLaunchedApp', function (evt) { 
    Ti.API.info('Tray Click Launched App (app was not running)'); 
    //alert('Tray Click Launched App (app was not running'); 
}); 

CloudPush.addEventListener('trayClickFocusedApp', function (evt) { 
    Ti.API.info('Tray Click Focused App (app was already running)'); 
    //alert('Tray Click Focused App (app was already running)'); 
}); 
+0

你使用的是什麼鈦版本? – Anand

+0

您好我正在使用鈦sdk版本2.1.3 –

+0

您好沒有模塊正在我的鈦上工作是否有任何問題與我的更新,因爲我有2.1.3 –

回答

1

IM也滿足了同樣的問題,甚至當我添加

<module platform="android">ti.cloudpush</module> 

,我刪除所有項目,並與延期包名鈦現在它正在創建新的項目,但我無法找到原因以前的代碼不起作用

0

瓦哈布,

修改tiapp.xml喜歡遵循和運行代碼。我已經複製了你的代碼,它運作良好。

<modules> 
     <module platform="commonjs" version="2.3.0">ti.cloud</module> 
     <module platform="android" version="2.0.7">ti.cloudpush</module> 
</modules>