arleyandrada / PushClient

FREE and Open Source - Titanium PushClient Module
Other
44 stars 17 forks source link

Error Alert shown in my sample android application #119

Closed sulthankareem closed 8 years ago

sulthankareem commented 8 years ago

Hi, I have purchased the module yesterday. I have created a sample android application, by just copy paste the app.js file u have given in github to my app.js file.Also i put the GCM sender ID. While i run the application it shows, the alert as "unable to register this device, SERVICE_NOT _AVAILABLE". Can u please explain , what is the issue with my app below , I added my app.js content

/**

//Workaround to Titanium Mobile issue #17030 //https://jira.appcelerator.org/browse/TIMOB-17030

var PushClient = require('br.com.arlsoft.pushclient');

var registerOptions = { GCMSenderId : 'XXXXXXXXXXXX', APNTypes : [ PushClient.NOTIFICATION_TYPE_BADGE, PushClient.NOTIFICATION_TYPE_ALERT, PushClient.NOTIFICATION_TYPE_SOUND ] };

var eventSuccess = function(event) { Ti.API.info('eventSuccess:' + JSON.stringify(event));

if (!event) {
    alert('Success:\n\nInvalid success');
    // Should never happen...
    return;
}

alert('Success:\n\nregistrationId\n\n' + event.registrationId);

};

var eventError = function(event) { Ti.API.info('eventError:' + JSON.stringify(event));

if (!event) {
    alert('Error:\n\nInvalid error');
    // Should never happen...
    return;
}

switch (event.code) {
case PushClient.ERROR_SENDER_ID:
    alert('Error:\n\nUndefined GCMSenderId');
    // Only for Google Cloud Messaging (Android)
    break;
case PushClient.ERROR_PLAY_SERVICES:
    alert('Error:\n\nGoogle Play Services not available\n\n' + event.error);
    // Only for Google Cloud Messaging (Android)
    break;
case PushClient.ERROR_NOT_SUPPORTED:
    alert('Error:\n\nNot supported error\n\n' + event.error);
    // Possible error messages for iOS:
    // - "Unable to run with iOS Simulator"
    // - "Unable to run with iOS in DEBUG mode"
    // - "Unable to run with iOS DEV profile due to Titanium Mobile issue
    // #17030"
    // Possible error messages for Android:
    // - "This device is not supported"
    break;
case PushClient.ERROR_REGISTER:
    alert('Error:\n\nUnable to register this device\n\n' + event.error);
    break;
case PushClient.ERROR_UNREGISTER:
    alert('Error:\n\nUnable to unregister this device\n\n' + event.error);
    break;
default:
    alert('Error:\n\nUnknown error\n\n' + JSON.stringify(event));
    // Should never happen...
}

};

var eventCallback = function(event) { Ti.API.info('eventCallback:' + JSON.stringify(event));

if (!event) {
    alert('Callback:\n\nInvalid callback');
    // Should never happen...
} else if (event.mode == PushClient.MODE_FOREGROUND) {
    alert('Callback in Foreground:\n\n' + JSON.stringify(event.data));
    // Push data received with app in foreground
} else if (event.mode == PushClient.MODE_CLICK) {
    alert('Callback from Click:\n\n' + JSON.stringify(event.data));
    // Push data received when user clicks in notification message
} else if (event.mode == PushClient.MODE_BACKGROUND) {
    // Requires set remote-notification UIBackgroundModes in tiapp.xml
    PushClient.endBackgroundHandler(event.data.handlerId);
    // Put the application back to sleep before any UI interations
    alert('Callback from Silent:\n\n' + JSON.stringify(event.data));
    // Push data received with app in background
} else if (event.mode == PushClient.MODE_ACTION) {
    alert('Callback from Action:\n\n'+event.category+'\n'+event.identifier+'\n\n' + JSON.stringify(event.data));
    // Push data received when user choose an action from notification message
} else {
    alert('Callback:\n\n' + JSON.stringify(event.data));
    // Should never happen...
}

};

PushClient.addEventListener(PushClient.EVENT_SUCCESS, eventSuccess); PushClient.addEventListener(PushClient.EVENT_ERROR, eventError); PushClient.addEventListener(PushClient.EVENT_CALLBACK, eventCallback);

PushClient.registerPush(registerOptions); var homeWindow = Ti.UI.createWindow({ url : 'ui/handheld/android/HomePage.js', exitOnClose : true, orientationModes : [Ti.UI.PORTRAIT], }); homeWindow.open(); homeWindow = null;

// PushClient.unregisterPush(); // Call this method to unregister

arleyandrada commented 8 years ago

Check my comments to these closed issues:

https://github.com/arleyandrada/PushClient/issues/83#issuecomment-101875859 https://github.com/arleyandrada/PushClient/issues/30#issuecomment-99749942

Regards,

Arley

sulthankareem commented 8 years ago

Thanks

sulthankareem commented 8 years ago

I understand the issue. Sorry for diturbing u