Titanium + GCM : INVALID_SENDER error - android

I'm new to Titanium app development. Now I'm trying to develop push notification app with GCM. I have done,
Registered in Google Cloud Console and created one project.
Created new server key.
Added those keys in ACS console.
Created test user in ACS console.
But still I'm getting the following error.
Faild to register for push!
INVALID_SENDER
My Titanium code:
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);
}
});
Can any one help me in this?
Thanks.

After you create a new project, you'll see at the top of the page something like this :
Project ID: elite-academy-627 Project Number: 152453929631
You need to register to GCM using the project number.

Related

Device token is blank when trying push notification by Cordova plugin for Firebase Cloud Messaging

I am tring to do push notification on my cordova android app with Cordova plugin for Firebase Cloud Messaging plugin. I have created and registered app in Google firebase console and downloaded google-services.json file and kept it in my project root folder. Then I am trying the functions provided in the plugin documentation on device ready but did not get the device token, it is blank. My cordova android version is 9.1.0. Can someone tell me why the device token is not generated? Please help me. My js code is below:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
cordova.plugins.firebase.messaging.onMessage(function (payload) {
console.log("New foreground FCM message: ", payload);
});
cordova.plugins.firebase.messaging.onBackgroundMessage(function (payload) {
console.log("New background FCM message: ", payload);
});
cordova.plugins.firebase.messaging.requestPermission({ forceShow: true }).then(function ()
{
console.log("You'll get foreground notifications when a push message arrives");
});
cordova.plugins.firebase.messaging.getToken().then(function (token) {
alert("Got device token: ", token);
});
/*cordova.plugins.firebase.messaging.onTokenRefresh(function () {
console.log("Device token updated");
});*/
cordova.plugins.firebase.messaging.createChannel({
id: "mypushid",
name: "Push channel",
importance: 3
});
}

firebase-x#ionic 4 not showing push messages (FCM)

I created this code in my app console:
app.compontent.ts
this.firebaseX.getToken().then(token => console.log('PUSH_TOKEN: GET_TOKEN: ', token))
.catch(err => console.log(err));
if (this.platform.is('ios')) {
this.firebaseX.grantPermission().then(hasPermission => console.log(hasPermission ? 'granted' : 'denied'));
this.firebaseX.onApnsTokenReceived().subscribe(token => console.log('PUSH_TOKEN: IOS_TOKEN: ' + token));
}
this.firebaseX.onMessageReceived().subscribe(message => console.log(message));
xCode configuration:
Chrome console after sending push message via firebase console:
xCode Console when app init:
2020-01-19 17:09:22.816015+0100 myApp[8896:2663293] registerForRemoteNotifications
2020-01-19 17:09:22.816107+0100 myApp[8896:2663293] _hasPermission: YES
...
2020-01-19 17:09:22.821477+0100 myApp[8896:2663036] PUSH_TOKEN: IOS_TOKEN: d2aac51a963530-FULL_TOKEN_HERE
2020-01-19 17:09:22.821807+0100 myApp[8896:2663036] PUSH_TOKEN: GET_TOKEN: frWxHosY-gQ:APA91bEk3-FULL_TOKEN_HERE
...
2020-01-19 17:13:46.395935+0100 myApp[8896:2663036] FCM direct channel = true
2020-01-19 17:15:39.418759+0100 myApp[8896:2663036] FCM direct channel = false
I'm running my app in debug env.
Current behavior:
Android:
Getting push messages only when app working is closed (im not using app) - it is possible to get push when app is running?
iOS:
Only getting APNS token, push will not showing. I checked double Settings -> notifications -> myApp Name -> everything is enabled. In Firebase console im using both tokens (from IOS_TOKEN and GET_TOKEN) both not working.
iOS: 13.3 (17C54)
xCode: 11.3 (11C29)
"cordova-plugin-firebasex": "^7.0.1"
What should i do to start receiving pushes on iOS?
I solved my problem.
I forgot to upload my .p8 key to firebase.
https://firebase.google.com/docs/cloud-messaging/ios/certs
Lesson learnt: always read documentation :)

Mobilefirst 8.0 cordova push notification device register failed

I took the sample Cordova project and added platform for Android environment then I created FCM project through Google console and then I got the sender id and server key. I added the MobileFirst server console credentials. Once I did the above steps I added the scope variable in the MobileFirst console "push.mobileclient". Finally I try to run my project using Android studio on an Android emulator.
The testing of the push notification failed while I clicked register device. Below are the error logs:
Failed to register device:"com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushException: Response: Status=400, Text: {\"errorCode\":\"invalid_client\",\"errorMsg\":\"Incorrect JWT format\"}, Error Message: Incorrect JWT format"
Kindly help me to resolve the issue.
Add these plugin in cordova project
cordova plugin add cordova-plugin-mfp
cordova plugin add cordova-plugin-mfp-push
Try to create fresh project in Firebase Console and add Server key & Sender ID in Mobilefirst console carefully.
Run in real device. Also use same network(wifi) in both Mobile and computer.
You can try without scope variable "push.mobileclient" in the MobileFirst console and try sample code:
sample code
function wlCommonInit(){
//initialize app for push notification
MFPPush.initialize (
function(successResponse) {
alert("Push Notification Successfully intialized");
MFPPush.registerNotificationsCallback(notificationReceived);
},
function(failureResponse) {
alert("Failed to initialize");
}
);
//Check device is Supported for push notification
MFPPush.isPushSupported (
function(successResponse) {
alert("Device is Push Supported");
},
function(failureResponse) {
alert("Failed to get push support status");
}
);
//register app for push notification
MFPPush.registerDevice( null,
function(successResponse) {
alert("Device Successfully registered");
},
function(failureResponse) {
alert("Failed to register");
}
);
var notificationReceived = function(message) {
alert(JSON.stringify(message));
};
}
Check here: Not able to send push notification to iOS devices through MFP Server V8 Console

Using Cordova-Plugin-FCMNotification I can get only token and no messages

I'm using this plugin in my ionic 1 project.
Follow what author wrote here.
I can get token from Google Firebase when i run my app on device, but I don't understand how register and get messages and push notifications..
Anyone have examples on how get push notifications directly from Google Firebase?
I have worked with the plugin cordova-plugin-fcm, with this plugin I used the code below to receive push notifications,the plugin documentation, you will need to download the file google-services.json and copy it to your android platform , make sure you have the following installed on you sdk, the documentation on the plugin has a lot of detail
Android Support Library version 23 or greater
Android Support Repository version 20 or greater
Google Play Services version 27 or greater
Google Repository version 22 or greater
FCMPlugin.getToken(
function (token) {
console.log(token);
},
function (err) {
console.log('error retrieving token: ' + err);
}
);
FCMPlugin.onNotification(
function(data){
console.log(JSON.stringify(data));
if(data.wasTapped){
console.log("=====================alert received on device tray and tapped by the user================"+JSON.stringify(data));
}else{
console.log("=====================alert received when app is open================"+JSON.stringify(data));
}
},
function(msg){
console.log('onNotification callback successfully registered: ' + msg);
},
function(err){
console.log('Error registering onNotification callback: ' + err);
}
);

AppGyver + Parse.com + GCM

I am currently struggling with implementing Push Notifications via Parse for an Android App with GCM .
Here is what i have and what works:
I followed the Readme Steps from the GitHub Project Push Notifications
I modified the registrationHandler to register the deviceToken:
var req = {
method: ‘POST’,
url: ‘api.parse.com/1/installations’,
headers: {
‘X-Parse-Application-Id’: ‘xxx’,
‘X-Parse-REST-API-Key’: ‘xxx’,
‘Content-Type’: ‘application/json’
},
data: {
‘deviceType’: ‘android’,
‘pushType’: ‘gcm’,
‘deviceToken’: deviceToken,
‘GCMSenderId’: senderID
}
}
$http(req).success(function(){
alert('Successfully registered');
}).error(function(){
alert('Error with Registration');
});
I have enabled Push Notifications in the Build Configuration and am able to build and install the apk.
In the Parse Core Module i can see the registered devices. I have added the Google Project ID and API Key to Parse.
If i copy the deviceToken from the Installation Table and use it with this Ruby Script, i receive a notification immediately.
require 'rubygems'
require 'pushmeup'
APPLICATION_API_KEY = "API_KEY_GOES_HERE"
DEVICE_REGISTRATION_ID = "REGISTRATION_ID_GOES_HERE"
GCM.host = 'https://android.googleapis.com/gcm/send'
GCM.format = :json
GCM.key = APPLICATION_API_KEY
destination = [DEVICE_REGISTRATION_ID]
data = {:message => "PhoneGap Build rocks!", :msgcnt => "1", :soundname => "beep.wav"}
puts GCM.send_notification( destination, data)
But I do not receive Notifications if i post them from Parse.
What am I missing?
Edit 1:
Meanwhile I had a look at LogCat and found that the messages are actually delivered to my device, but something in the processing of the message goes awry:
D/JsMessageQueue﹕ Enqueued JsMessage: {"from":"123456789","collapse_key":"do_not_collapse","payload":{"data":{"alert":"Testing for UUID","push_hash":"c1a7d096f1157109a590dbade5670dcd"}},"foreground":true,"coldstart":false,"timestamp":"2015-05-19T07:57Z","uuid":"f00dfc28-ef88-411c-b12d-f3eb5dba230b"}, paused: false
05-19 09:57:48.038 24772-24772/ch.hevs.asd D/JsMessageQueue﹕ Flushed 1 messages to JS side.
05-19 09:57:48.038 24772-28185/ch.hevs.asd V/GCMBaseIntentService﹕ Releasing wakelock
05-19 09:57:48.058 24772-24772/ch.hevs.asd I/chromium﹕ [INFO:CONSOLE(1044)] "processMessage failed: Error: SyntaxError: Unexpected token u", source: http://localhost/cordova.js (1044)
05-19 09:57:48.078 24772-24772/ch.hevs.asd I/chromium﹕ [INFO:CONSOLE(1045)] "processMessage failed: Stack: SyntaxError: Unexpected token u
at Object.parse (native)
Edit 2:
Ok, i debugged both incoming push notifications and the JSON i receive from both methods are different. So i think the PushPlugin from Cordova is not able to handle the JSON from Parse.com
Message from Ruby:
S11 PushPlugin1887095744
{"soundname":"beep.wav",
"msgcnt":"1",
"from":"12345678",
"message":"PhoneGap rocks!",
"collapse_key":"do_not_collapse",
"payload":{},
"foreground":false,
"coldstart":false,
"timestamp":"2015-05-19T08:29Z",
"uuid":"af6605e0-1efb-4c8a-82de-d8858b2ec725"}
Message from Parse
S11 PushPlugin1887095744
{"from":"12345678",
"collapse_key":"do_not_collapse",
"payload":{
"data":{"alert":"lets debug this PoS",
"push_hash":"1edebeb8864bc06682c10f1be1058164"}},
"foreground":false,
"coldstart":false,
"timestamp":"2015-05-19T08:25Z",
"uuid":"df575996-c039-4f5b-8120-147fb47911c9"}

Categories

Resources