Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (android)
Viewing all articles
Browse latest Browse all 7655

Integrating Cloud Push Notification using Alloy

$
0
0

Am using 3.2.2.GA sdk, Android and Appcelerator Cloud for my applications push notification. When I create a Default mobile application and run, push notifications are working fine. But if I run the same code in Alloy project with configuration too am getting error as Sender ID problem. Will push wont work in Alloys or else is something I have to look for,

index.xml

<Alloy>
    <Window class="container">
        <Label id="label" onclick="">Hello, World</Label>
    </Window>
</Alloy>
index.js
var CloudPush = require('ti.cloudpush');
CloudPush.debug = true;
CloudPush.showTrayNotificationsWhenFocused = true;
CloudPush.focusAppOnPush = false;
 
    var deviceToken;
 
    var Cloud = require('ti.cloud');
    Cloud.debug = true;
 
 
function test(){
        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: 'xxxxxx',
        password: 'xxxxxx'
    }, 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)');
});
Really I am unable to figure out whats affecting the code not to register for Push. And I made all settings as I did for Default Mobile App.

Viewing all articles
Browse latest Browse all 7655

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>