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

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 :)

Related

Push notifications not being received by Android or iOS physical or emulator/simulator devices

My project heavily relies on push notifications or FCM messages for VoIP & messaging features. The issues is these notifications aren't being received by any device when sending a cloud-messaging test message.
Project on Github to view code directly (excluding GoogleServices files): Github Here
Creating a fresh flutter project + firebase project, I performed the following steps:
Create Flutter project, using com.company.pushnotifications + add firebase & messaging deps (ref)
Created a Firebase project
Create Android Firebase App, download GoogleServices.json and place into android/app folder + add required android/build.gradle + android/app/build.gradle plugins (source)
Create iOS Firebase App, download GoogleService-Info.plist, copy into Runner folder using Xcode specifically.
Configure iOS app identity + provisioning profile + APNS key (installed into Firebase Cloud Messaging) with Push notifications + enable Background (fetch + notification) capabilities & push notifications capabilities
do not swizzle notifications by adding the following to the Info.plist file:
Info.plist file:
FirebaseAppDelegateProxyEnabled -> NO (Boolean)
edit ios/Runner/AppDelegate.swift with the following content:
AppDelegate.swift content:
import UIKit
import Flutter
import Firebase // added this line
#UIApplicationMain
#objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure() //add this
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
Setup firebase messaging with the following flutter code:
I'm debugging with breakpoints in background & foreground messages, left it for 2 hours incase the messages were delayed but on not one of the debugging sessions did a breakpoint trigger indicating a message was received
main.dart file:
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
// If you're going to use other Firebase services in the background, such as Firestore,
// make sure you call `initializeApp` before using other Firebase services.
await Firebase.initializeApp(); // breakpoint for debugging placed here
print("Handling a background message: ${message.messageId}");
}
void main() async {
WidgetsFlutterBinding.ensureInitialized();
FirebaseApp defaultApp = await Firebase.initializeApp();
// source: https://firebase.flutter.dev/docs/messaging/usage#background-messages
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
// source: https://firebase.flutter.dev/docs/messaging/usage#foreground-messages
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
print('Got a message whilst in the foreground!'); // breakpoint for debugging placed here
print('Message data: ${message.data}');
if (message.notification != null) {
print('Message also contained a notification: ${message.notification}');
}
});
runApp(MyApp());
}
When sending a test push notification using Cloud Messaging Test notifications, I expect the notification to show on Android (emulated or physical atleast), but it does not show on either iOS or Android (emulated or physical).
To my knowledge I've followed the documentation as required - did I miss something or is something broken?

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.

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);
}
);

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