Unable to configure push notification for android in Titanium - android

To implement push notification service in my titanium app for android, I was going through this development document. At first, I configured push services for android device by creating a "Client ID". I saved the "Client ID" for further use, but i do not understand where this "Client ID" would be need as there is no information for this in the doc. Then I followed this doc to subscribe push notification and added "ti.cloudpush" module to the tiapp.xml. But unfortunately, I'm getting error while calling retrieveDeviceToken() method. Here is my code snippet -
// Require the module
var CloudPush = require('ti.cloudpush');
var deviceToken = null;
// 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) {
deviceToken = e.deviceToken;
}
function deviceTokenError(e) {
alert('Failed to register for push notifications! ' + e.error);
}
// Process incoming push notifications
CloudPush.addEventListener('callback', function (evt) {
alert("Notification received: " + evt.payload);
});
And here is the error I'm getting in the console -
Failed receiving GCM SenderId. Getting GCM SenderId failed. Max retry time reaches.
Note - I didn't add anything for android manifest in tiapp.xml

When you're using Cloudpush module you will also need to configure the backend with settings. You can find how to do that in the documentation: https://docs.appcelerator.com/platform/latest/#!/guide/Configuring_push_services-section-src-37551713_Configuringpushservices-ConfiguringpushservicesforAndroiddevices
If you want to use your own backend you will need to use a different module for sending push notifications on Android. For example ti.goosh or onesignal
The documentation of both modules will tell you how to configure the senderID.

Related

Implementing Ti.goosh push notification module in Titanium for Firebase support

I have implemented Ti.goosh module in my app for sending push notification from Firebase. I followed this git document and created a new project in Google Developer Console API. I got a Project Number from there and used it as "GCM sender ID" in tiapp.xml. Then I added following code in my index.js controller.
var TiGoosh = require('ti.goosh');
TiGoosh.registerForPushNotifications({
// The callback to invoke when a notification arrives.
callback: function(e) {
var data = JSON.parse(e.data || '');
},
// The callback invoked when you have the device token.
success: function(e) {
// Send the e.deviceToken variable to your PUSH server
Ti.API.log('Notifications: device token is ' + e.deviceToken);
},
// The callback invoked on some errors.
error: function(err) {
Ti.API.error('Notifications: Retrieve device token failed', err);
}
});
When I run app, success block execute and i got the device token. But I didn't get the message from firebase. I also couldn't understand where the server key and API key from firebase should be included in this module to link with my app.
How can I understand the whole thing? It seems that push notification in Titanium is very complex with very poor documentation.
Use this php script to send notification and confirme you receive the data with ti.goosh
you need to include your api key and device token (registration_ids) in the script

push notification with cordova and firebase Cloud messaging:registrationID keep changing

Using cordova plugin ktekosi-phonegap-plugin-push, I get the registrationID
var push = PushNotification.init({ "android": {"senderID": "my sender ID"}});
push.on('registration', function(data) {
console.log(data.registrationId);
document.getElementById("fcm_id").innerHTML = data.registrationId;
});
So I can use it by the server to send notification through FCM.
How can I get this registrationID fixed for all time? Is this an app specific ID or a user specific ID?
Push registration ID will be changed with time. This is an usual case. This is neither an instance of the installed application nor app-specific or user-specific id.
When an app comes online you need to fetch the push registration ID and then pass it to your backend server each time to keep your backend server updated with the push registration ID.
Your backend server will then generate a push notification and will send it to FCM with the specific push registration ID it has. FCM then manages receiving the push notification in your mobile application.
I've answered a question here telling how push notification system works. You might have a look.
Update
Looks like google has changed its new gcm library as the answer stated here - https://stackoverflow.com/a/16839326/3145960. You might take a look at here. So, as I've read, the push registration id is updated only when app receives an update or the android os gets updated. Its much simpler now.
Try to use this plugin "cordova plugin add cordova-plugin-fcm". You can find detail here
To get Registration ID Use it like this
<script type="text/javascript">
function onLoad() {
document.addEventListener("deviceready", Fire, false);
}
function Fire() {
FCMPlugin.getToken(
function (token) {
alert(token)
},
function (err) {
alert("Error: " + 'error retrieving token: ' + err);
}
);
};
</script>
<body onload="onLoad();">

InvalidRegistration error with GCM (Android) and PhoneGap

I am using phonegap-plugin-push with Android. Although I'm successful in registering the device, I cannot successfully deliver a notification using the registrationId returned by the plugin.
var push = PushNotification.init({
android: {
senderID: "XXXXXXXXXXXX"
}
});
push.on('registration', function (data) {
alert('registrationId: ' + data.registrationId);
});
The alert upon registration reads registrationId: dYeoRp-FIWc:APA91bExJIUVGgpqOh8NNRJ7Ua9vHun7ECN8JWBisFTzrxRYbC1C4cjEpnNsmxzCd7f0o8Hu6Fhp-nrQa5Efw95vtduJKi_o9H2NxeOJUCSX10z48sgDxWmHU7LVbOBa-vZjZVwouhc9.
An attempted push returns the following:
{"multicast_id":6855504054873897650,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
What are you using to send the push notification? Whatever tool you're using may not like the special characters in the registrationId.

How to send GCM device token to IBM Bluemix

I am getting device token from GCM. But in IBM Bluemix Cordova documentation,they are never sending Device Token.
Then how will the device will be registered in Bluemix for individual push notification.
Link to Cordova Blemix Doc - DOCUMENTATION
When you register the device with the Bluemix Push service, the success message returned will contain the Device ID.
var success = function(message) { console.log("Success: " + message); };
var failure = function(message) { console.log("Error: " + message); };
MFPPush.registerDevice({}, success, failure);
Is that what you mean by Device Token?
Update
The GCM service provides the Device token which the SDK validates and updates with the Bluemix Push service.
You can find more details and an extensive timeline outlining the process # https://github.com/ibm-bluemix-mobile-services/bms-clientsdk-cordova-plugin-push
Scroll down to "Push Notification SDK flows for hybrid Android Apps"

How to send/receive push notifications from ionic mobile app?

I have a messaging app built using the Ionic framework (on cordova). I plan on building this for android, and I'd like a way to send and recieve push notifications from the app using javascript/ionic.
Are there any good tutorials out there on how to go about setting something like this up?
There is example application made available by Holly Schinsky. The core of it is the usage of PushPlugin which is the standard method to handle push notifications on Cordova. There is quite extensive tutorial provided for this subject on their documentation on that GitHub repository. The main method is pushNotification.register which registers the device to listen for push notifications.
If you instead need to trigger notification locally, you might want to take a look at Local notification plugin instead. With it you can add notifications to be shown on the device without the need for external services to send the push notifications.
Use this plugin https://github.com/phonegap-build/PushPlugin.
Android devices receive push notifications through the Google Cloud Messaging (GCM) service, whereas iOS devices receive them from the Apple Push Notifications (APN) Service.
The way the notifications are received (by sound, alert etc) is a combination of the options set in the application code upon registration as well as the user’s device settings for notifications.
If you want more specific follow below tutorial :
http://devgirl.org/2013/07/17/tutorial-implement-push-notifications-in-your-phonegap-application/
ngCordova has a plugin that supports Push Notifications. It has sample code for iOS and Android. Check it out: http://ngcordova.com/docs/plugins/pushNotifications/
The latest phonegap-plugin-push allows you to register and receive push notifications in your ionic apps. It is maintained at the following Github link:
https://github.com/phonegap/phonegap-plugin-push
Installation:
cordova plugin add https://github.com/phonegap/phonegap-plugin-push --variable SENDER_ID="XXXXXXX"
Where the XXXXXXX in SENDER_ID="XXXXXXX" maps to the project number in the Google Developer Console. To find the project number login to the Google Developer Console, select your project and click the menu item in the screen shot below to display your project number.
If you are not creating an Android application you can put in anything for this value.
Note: You may need to specify the SENDER_ID variable in your package.json.
"cordovaPlugins": [
{
"variables": {
"SENDER_ID": "XXXXXXX"
},
"locator": "phonegap-plugin-push"
}
]
Note: You need to specify the SENDER_ID variable in your config.xml if you plan on installing/restoring plugins using the prepare method. The prepare method will skip installing the plugin otherwise.
<plugin name="phonegap-plugin-push" spec="1.6.0">
<param name="SENDER_ID" value="XXXXXXX" />
</plugin>
After installation you can now add code below to your main javascript file to register and receive push notifications:
$ionicPlatform.ready(function () {
var push = PushNotification.init({
android: {
senderID: "XXXXXXX"//, //project token number (12 digit) from https://console.developers.google.com
// forceShow: "true", //force show push notification when app is in foreground on Android only.
},
browser: {
pushServiceURL: 'http://push.api.phonegap.com/v1/push'
},
ios: {
/*senderID: "XXXXXXX",*/ //If using GCM for ios, project token number (12 digit) from https://console.developers.google.com
/*gcmSandbox: 'true',*/ //If using GCM for ios
alert: 'true',
badge: 'true',
sound: 'true',
},
windows: {}
});
PushNotification.hasPermission(function (permissionResult) {
if (permissionResult.isEnabled) {
$log.debug("has permission for push notification");
/*Register device with GCM/APNs*/
push.on('registration', function (data) {
// data.registrationId
$log.debug("data.registrationId: " + data.registrationId);
});
push.on('notification', function (data) {
// data.message,
// data.title,
// data.count,
// data.sound,
// data.image,
// data.additionalData
$log.debug(JSON.stringify(data));
});
push.on('error', function (e) {
// e.message
$log.debug("e.message: " + e.message);
//alert(e.message);
});
}
});
}
}

Categories

Resources