AppGyver + Parse.com + GCM - android

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"}

Related

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

Android doesn't receive push notifications from new Parse Server

I'm migrating my Android and iOS apps from parse.com to Parse Server (by the way I'm using a Parse test app but I guess it's not relevant to this issue). After the migration, everything is working well but the push notifications to Android device (they are working well to my iOS app).
This is what I've done so far.
1. In my Parse Server code (on Digital Ocean by the way), in /home/parse/index.js I've initialized Parse Server this way:
var api = new ParseServer({
databaseURI: databaseUri || '<my mongodb url>',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || '<my app ID>',
masterKey: process.env.MASTER_KEY || '<my master Key>',
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse',
push: {
android: {
senderId: '<my GCM sender Id>',
apiKey: '<my GCM API Key>'
},
ios: [{
pfx: '/home/parse/<my dev P12>',
passphrase: '',
cert: '',
key: '',
bundleId: '<my bundle ID>',
production: false
},
{
pfx: '/home/parse/<my prod P12>',
passphrase: '',
cert: '',
key: '',
bundleId: '<my bundle ID>',
production: true
}]
}
});
I’ve taken "my GCM sender ID" from my Google Developer Consoler, it’s the 12 digits number from Settings > Project number.
I’ve tried with 3 different "my GCM API Key", one without app restrictions, one available only for my android/debug.keystore and one available only for my app keystore.
I’ve checked that I have selected this app in my Google Developer console and that my package id is correct in all places.
2. Once I’ve made this change I’ve restarted Parse Server with
pm2 delete all // this with parse user
pm2 start ecosystem.json // this with parse user
pm2 save // this with parse user
sudo service nginx restart //this with my sudo user
3. In Android I’m initializing Parse this way:
public static void initParse(Application app) {
ctxt = app.getApplicationContext();
Parse.enableLocalDatastore(app);
// Old version
Parse.initialize(app, "<my app id>", "<my client key>");
// New version
//Parse.initialize(new Parse.Configuration.Builder(ctxt)
// .applicationId("<my app id>")
// .clientKey(null)
// .server("https://<my new server>/parse/")
// .build()
//);
ParseUser.enableRevocableSessionInBackground();
}
I’m not initializing with the new method because it’s crashing (this is the issue of another question Android switch from Parse to Parse Server crashes), but I guess this initialization doesn’t affect the push notifications.
4. In Android I’ve added this to my Android Manifest:
<meta-data android:name="com.parse.push.gcm_sender_id"
android:value="id:<my GCM sender Id>" />;
The rest of my manifest and my GCM configuration is the same I had before the migration.
5. And as a summary.
With old parse.com push notifications worked well with Android and iOS.
With new Parse Server and the code described above iOS push notifications are working well.
With new Parse Server and the code described above Android push notifications are not being received.
With my new Parse Dashboard installed in Digital Ocean when sending push notifications both to iOS and to Android Dashboard gives a Saved! what makes me thing it’s a problem with my Android app and not with my Parse Dashboard/Parse Server configuration.
What am I missing here?
Make sure that your Parse SDK libraries are updated!
I was having a bunch of trouble getting Android notifications pushed from Parse Dashboard too, but it was all resolved when I updated my libraries to Parse 1.13.0 and Bolts 1.4.0.
you can try using "CURL" to specified only "android" device.
curl -X POST \
-H "X-Parse-Application-Id: you_app_id" \
-H "X-Parse-Master-Key: your_master_key" \
-H "Content-Type: application/json" \
-d '{
"where": {
"deviceType": {
"$in": [
"android"
]
}
},
"data": {
"title": "The Shining",
"alert": "All work and no play makes Jack a dull boy."
}
}'\ http://your_server_address/parse/push
Then you can find out the exactly what is wrong.

Ionic Push: GCM project number not found in android application

I'm trying to use ionic.io to send push notification. Here is what I did :
Create an app in GCM and enable GCM API.
Create credentials and get the api key.
Create an app in ionic.io dashboard
Create a security profile and add the api key
Create an api token in ionic.io dashboard
My source code in app.js which generated by ionic start pushdemo
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
var push = new Ionic.Push({
"debug": true
});
push.register(function(token) {
alert(token.token);
console.log("Device token:",token.token);
push.saveToken(token);
});
7.Add push plugin:
ionic plugin add phonegap-plugin-push --variable
SENDER_ID="myproject_number"
I tried both with or without quotation mark around myproject_number. It's the project number in step 1.
8.Set the dev_push to false
9.Hook my app to ionic.io by ionic io init
10.Run ionic run android -lc
Found the following error message:
What's wrong with it? Can anybody help? Thanks.
i had the same problem its generally because of proxy issue
you are behind the proxy it means you are using internet by making request to the server ,so first you should use your own internet (in this case if you use WIFI
then also it will work )
second aafter creating your project dirsctly make login from your cinsole to ionic io
it will ake for email and password that will make your app live
third
ionic plugin add phonegap-plugin-push --variable SENDER_ID="myproject_number"
use quotes for entering your project number.project number also called GCM number and your server key is the key you generated in same project means google console which enable you to use google services.
and dont forget to add android platform
ionic start pushCall
ionic login
ionic upload
//open google console
1-create project
2-use google api
1-mobile APIs
2-select google cloud messaging and eneble it
3- go to credential and create API key
//after that add following plugin
ionic add ionic-platform-web-client
ionic plugin add phonegap-plugin-push --variable SENDER_ID="991785317333"
(dont remove quotes while adding gcm number)
//add platfom
ionic platform add android
ionic io init
ionic config set dev_push true
//open ionic io
go to setting
1-create api key
2-go to certificate and create security profile name edit id click on android and add GCM key
and save it.
//add this code to app.js
angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
var push = new Ionic.Push({
"debug": true
});
push.register(function(token) {
console.log("My Device token:",token.token);
push.saveToken(token); // persist the token in the Ionic Platform
});
});
})
//to test wether your configure correctly with ionic io open launch postman
//and then do the following things:
1-create collection give it a valid name
2-in body click on text and select Application/json
it will add header automatically
3-add another header
key as Authorization
value as bearer followed by your api token from ionic io
4-select "raw " as the format of our json
2-in body section of your collection write
following code
{
"tokens": ["DEV_DEVICE_TOKEN"],
"profile": "PROFILE_NAME",
"notification":
{
"message": "This is my demo push!"
}
}
//now it will prompt message on browser
ionic config set gcm_key
ionic config set dev_push false
ionic build android
install your app in mobile and send the notification from postman
(Mahesh Sampat Nighut)
navi mumbai
add this code in your app.js
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
var push = new Ionic.Push({
"debug": true
});
push.register(function(token) {
console.log("My Device token:",token.token);
push.saveToken(token); // persist the token in the Ionic Platform
});
});
})
and dont forget to run below command
ionic config set dev_push true
when you are testing it on browser make above cammand true,this means developmant mode ,and when you are making apk this time you have to make above command false

Titanium + GCM : INVALID_SENDER error

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.

Categories

Resources