0
我已經能夠註冊移動設備並訂閱Titanium中的頻道。當移動設備收到2個推送通知並且用戶點擊其中一個通知時。Titanium Appcelerator推送通知回叫不止一次
回調被稱爲兩次。我如何知道它被點擊的通知或我如何知道推送通知的總數正在等待?
var CloudPush = require('ti.cloudpush');
//CloudPush.singleCallback = true;
// 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) {
//CloudPush.enabled = true;
deviceToken = e.deviceToken;
subscribeToChannel();
//sendTestNotification();
}
function deviceTokenError(e) {
//alert('Failed to register for push notifications! ' + e.error);
}
// Triggered when the push notifications is in the tray when the app is not running
CloudPush.addEventListener('trayClickLaunchedApp', function(evt) {
CloudPush.addEventListener('callback', function(evt) {
var title = JSON.parse(evt.payload);
});
});
// Triggered when the push notifications is in the tray when the app is running
CloudPush.addEventListener('trayClickFocusedApp', function(evt) {
CloudPush.addEventListener('callback', function(evt) {
var title = JSON.parse(evt.payload);
});
});
var Cloud = require("ti.cloud");
function subscribeToChannel() {
// Subscribes the device to the 'test' channel
// Specify the push type as either 'android' for Android or 'ios' for iOS
//alert(deviceToken+"ss");
Titanium.App.Properties.setString("token", deviceToken);
Cloud.PushNotifications.subscribeToken({
device_token : deviceToken,
channel : 'test',
type : Ti.Platform.name == 'android' ? 'android' : 'ios'
}, function(e) {
if (e.success) {
//alert('Subscribed');
} else {
alert('Error:\n' + ((e.error && e.message) || JSON.stringify(e)));
}
});
}
感謝您的回覆。如果用戶清除托盤圖標中的通知並僅運行應用程序,則回調仍將執行。因此,我將回調包裝在trayClickLaunchedApp,trayClickFocusedApp函數中。但是,如果我們有兩個通知未決並且用戶點擊它們,那麼兩個回調都會執行兩次。 – Vidya