Unable get message on IOS from firebase console with phonegap plugin - ios

i have successfully implemented Firebase cloud messaging in my phonegap app with phonegap-plugin-push on IOS, i am receiving token from Firebase on register event, i print it in alert message and it shows me token.
Below is my code
function onDeviceReady(){
var push = PushNotification.init({
"android": {
"senderID": "29271112133",
sound: true,
vibrate: true
},
"ios": {"senderID": "29271112133","alert": "true", "badge": "true", "sound": "true"},
"windows": {}
});
push.on('registration', function(data)
{
globalpushtoken1 = data.registrationId;
alert("Token IS HERE.. "+globalpushtoken1);
checktoken(data.registrationId);
});
push.on('notification', function(data) {
if(data.additionalData.coldstart){
if(data.title=="New Offer !"){
window.location.replace("#offerspage"); }
}
});
push.on('error', function(e) {
alert("Push Error");
console.log("push error");
});
Now the problem is when i try to send some test message from firebase console and select User segment and select my app and send message it shows message status as completed however i dont get any notification on real device, and if i send the message to specific device using token of that device then it shows status as
FAILED Unregistered registration token " I am new to firebase and phonegap, please help me resolve this.
firebase console after sending message manually

Related

Data only messages not receiving on iOS device using Firebase Messaging and React Native

I am sending data only messages from a Firebase Function to a React Native app.
It works on Android, but it not works on iOS.
As specified here https://rnfirebase.io/messaging/usage#data-only-messages
my code for sending a message is the following:
var payload = {
data: {
//my app data
},
apns: {
payload: {
aps: {
contentAvailable: true,
priority: 'high',
},
},
headers: {
'apns-push-type': 'background',
'apns-priority': '5',
'apns-topic': 'com.xxxx.xxxx', //my app bundle id
},
},
tokens: tokens
};
const response = await admin.messaging().sendMulticast(payload);
The response has success=true, so the code is working.
In my iOS app I have this handler:
const setMessages = useCallback(async (remoteMessage: any) => {
console.log('A new FCM message arrived!', JSON.stringify(remoteMessage));
});
useEffect(() => {
const unsubscribe = messaging().onMessage(setMessages);
return unsubscribe;
}, []);
As I said before, it works on Android. In iOS the callback is never triggered.
I am pretty sure I setup the iOS app correctly:
- I can receive notification-only messages in iOS
- I can generate the fcm token

how to add custom sound in iOS with flutter?

I am new to push notifications and I have this task to add a custom sound whenever the user receives a notification. I am not using flutter local notifications, just the normal firebase configurations and its working well. Can anyone help me add a custom sound for iOS. Any help would be greatly appreciated!
Here is the payload used and the firebase configurations.
options = {
"notification": {
"title": formatter.title,
"body": formatter.body,
"sound": "notification.caf",
"content_available": true,
},
"priority": "high",
"data": {
"badge": user.unopened_notification_count,
"body": formatter.body,
"title": formatter.title,
"id": notification.id,
"notifiable_type": notification.notifiable_type,
"notifiable_id": notification.notifiable_id,
"click_action": "FLUTTER_NOTIFICATION_CLICK"
}
}
also here is my firebase configuration:
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
if (Firebase.apps.isEmpty) await Firebase.initializeApp();
print('Handling a background message ${message.data['id']}');
}
handleNotifications() async {
FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(badge: false, alert: false, sound: true); //presentation options for Apple notifications when received in the foreground.
FirebaseMessaging.onMessage.listen((message) async {
print('Got a message whilst in the FOREGROUND!');
return;
}).onData((data) async {
print('Got a DATA message whilst in the FOREGROUND!');
print('data from stream: ${data.data['id']}');
});
FirebaseMessaging.onMessageOpenedApp.listen((message) async {
print('NOTIFICATION MESSAGE TAPPED');
return;
}).onData((data) async {
print('NOTIFICATION MESSAGE TAPPED');
print('data from stream: ${data.data}');
});
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
FirebaseMessaging.instance.getInitialMessage().then((value) => value != null ? _firebaseMessagingBackgroundHandler : false);
return;
}
attached image here is where I placed the sound file inside Xcode

Push notifications with Ionic and Firebase on iOS

I've used these instructions to setup Push notifications with Firebase on iOS. I'm pretty sure I've setup all the Apple certificates correctly and I can sent the notifications from FCM (Firebase Cloud Messaging) just fine, and the status is "sent", but they never arrive in my iPhone.
https://ionicframework.com/docs/native/push/
Here's my code. Any advice why this is not working or how to debug it will be highly appreciated!! Many thanks!
import { Push, PushObject, PushOptions } from '#ionic-native/push';
constructor(platform: Platform, private push: Push, public alertCtrl: AlertController) {
platform.ready().then(() => {
StatusBar.styleDefault();
Splashscreen.hide();
this.pushNotifications();
});
}
pushNotifications() {
this.push.hasPermission().then((res: any) => {
if (res.isEnabled) { console.log('We have permission to send push notifications');}
else { console.log('We do NOT have permission to send push notifications'); }
}).catch((error) => { console.log("Push Notification needs Cordova: " + JSON.stringify(error));});
const options: PushOptions = {
android: {
senderID: 'My_ID'
},
ios: {
alert: 'true',
badge: true,
sound: 'false'
},
windows: {}
};
const pushObject: PushObject = this.push.init(options);
pushObject.on('notification').subscribe((notification: any) => {
if(notification.additionalData.foreground) {
let youralert = this.alertCtrl.create({
title: 'New Push notification',
message: notification.message
});
youralert.present();
}
});
pushObject.on('registration').subscribe((registration: any) => console.log('Device registered', JSON.stringify(registration)));
pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));
}
You should add the FCM plugin find in the link:
https://ionicframework.com/docs/native/fcm/
Then after find the below file in plugin :
“AppDelegate+FCM”
Where you can find the below method:
customDidFinishLaunchingWithOptions
Please replace below :
[FIRApp configure];
with this
// [START configure_firebase]
if(![FIRApp defaultApp]){
[FIRApp configure];
}
Have you tried to send your push notifications from online apns tester tools?
(like. http://pushtry.com/). If you still have the same problem check your ios certificates, configurations and device checks again.

GCM registrationId is not received on phonegap push plugin

Couple days ago I had an issue with getting APNS token instead of GCM token while using phonegap push plugin.
Well, I changed setup, I've put senderID in [ios] block, recompiled the app. Now I dont get ANY regustrationId at all on Iphone. It still works fine on Android. Can anyone tell me what can be a problem?
Here is setup of plugin:
var push = PushNotification.init({
android: {
senderID: "8225....8910"
},
ios: {
senderID: "8225....8910",
alert: "true",
badge: "true",
sound: "false"
},
windows: {}
});
And this event is never being called:
push.on('registration', function(data) {
$.ajax({
url: '/authentication/ajax-register-gcm-token/',
data: {token: data.registrationId},
success: function (json) {
alert('Phone registered' + data.registrationId);
}
});
});
The code you have used to initialize Push Notification Plugin Object is wrong. It should be as below:
var push = PushNotification.init({
android: {
senderID: "XXXXXXXXXXXX",
},
ios: {
alert: "true",
badge: "true",
sound: "true",
}
});
push.on('registration', function(data) {
console.log(data.registrationId);
registerDeviceToken(data.registrationId);
});
push.on('notification', function(data) {
console.log("notification event");
alert(JSON.stringify(data));
});
push.on('error', function(e) {
console.log("push error");
alert(JSON.stringify(e));
});
function registerDeviceToken(deviceToken){
//Register the registrationId or deviceToken to your server as per the webservice type and parameters configuration set
//From your code snippet above
$.ajax({
url: '/authentication/ajax-register-gcm-token/',
data: {token: deviceToken},
success: function (json) {
alert('Phone registered' + deviceToken);
}
});
}
There is no SenderID mentioned here in official link as well. Make sure you have turned on Push Notification service under Capabilities section of your Project and you have put correct development and production APNS p12 files and their respective passwords at the server side code. So if you are running App with Development Profile then there should be development p12 file environment sending Push Notification in order to be received on your iOS device. To set up Development and Production APNS p12 certificate, refer this link: APNS setup

Phonegap Plugin Push notification stays in tray when clicked on iOS

I built a phonegap application which receives push notifications. When I run the application on Android, everything works perfectly, but when I run it on iOS, the push notifications stay in the notification tray after clicking them.
I am using Phonegap Push Plugin for the Phonegap application and I'm using PushSharp for sending the notification. This is my code:
var push = PushNotification.init({
"android": { "senderID": "XXXXXXXX", "icon":"pushicon" },
"ios": { "alert": "true", "badge": "true", "sound": "true"},
"windows": {}
});
push.on('registration', function(data) {
var deviceInfo = {
notificationId: data.registrationId,
phonePlatform: device.platform,
phoneVersion: device.version,
phoneModel: device.model
}
info = $.extend(info, deviceInfo);
localStorageService.setDeviceInfo(info);
});
push.on('notification', function (data) {
alert(data.additionalData.title);
});
push.on('error', function(e) {
console.log('Something went wrong: ' + e.message);
});
I've also tried calling push.finish(), but it makes no difference.
Does anybody know how I can make sure a notification on the notification tray dissapears after clicking on it?
Specs
Device: iPod Touch with iOS 7.0.4
Plugin: Phonegap plugin push
On iOS 8 and greater, when you tap the push it will be deleted from notification center, but on iOS 7 and older it doesn't work that way.
If you want to delete the push notification from notification center you'll have to set the badge to 0.
push.setApplicationIconBadgeNumber(function() {
console.log('success');
}, function() {
console.log('error');
}, 0);
If it doesn't work you can try to set it to a greater number first and then to 0
push.setApplicationIconBadgeNumber(function() {
push.setApplicationIconBadgeNumber(function() {
console.log('success');
}, function() {
console.log('error');
}, 0);
}, function() {
console.log('error');
}, 2);
Latest version of the plugin also has a clearAllNotifications method:
push.clearAllNotifications(function() {
console.log('success');
}, function() {
console.log('error');
});
Or you can also pass the clearBadge option to the init method
var push = PushNotification.init({
"android": { "senderID": "XXXXXXXX", "icon":"pushicon" },
"ios": { "alert": "true", "badge": "true", "sound": "true", clearBadge: "true" },
"windows": {}
});

Resources