Phonegap, IOS , Device doesn't receive notification - ios

I am developing a Phonegap application for iOS and would like to enable push notifications. I use GCM and when I send notification google return me success but IOS device doesn't show anything .
There is my code:
"android": {
"senderID": "xxxxxxxx", "icon": "icon", "badge": "true", "iconColor": "white", "sound": "true", "soundname": "nb"
},
"ios": {
"senderID": "xxxxxxxx",
"alert": "true",
"badge": "true",
"sound": "true",
"usesGCM":true,
"sandbox":false,
},
"windows": {}
.

First of all install the plugin of push notification.
phonegap plugin add phonegap-plugin-push
After the write the java script code as below for iOS push
var note = new apn.Notification();
note.badge = 1;
note.sound = "beep.wav"; //path to your sound
note.contentAvailable = 1;
note.alert = { "body" : msg, "action-loc-key" : "Show Me!" , "launch-image" : "mysplash.png"};
//note.payload = {'uuid': data.uuid}; // additional payload
note.device = data.deviceId;
var callback = function(errorNum, notification){
console.log('Error is: %s', errorNum);
//console.log("Note " + JSON.stringify(notification));
}
var options = {
gateway: 'gateway.sandbox.push.apple.com',
errorCallback: callback,
cert: 'test.pem',
key: 'test.pem', // ** NEED TO SET TO YOURS
passphrase: '', // ** NEED TO SET TO YOURS
//port: 2195,
enhanced: true,
cacheLength: 100
}
var apnProvider = new apn.Provider(options);
apnProvider.send(note, myDevice).then( (result) => {
console.log("Result :: ",JSON.stringify(result));
});
It will works.

Related

Flutter with Firebase Messaging. iOS device doesn't receive data only messages

I'm sending data-only message from Cloud functions
I tried this solution: https://github.com/FirebaseExtended/flutterfire/issues/3395#issuecomment-683973108
Here are the option sendings from Cloud Functions:
{
android: {
priority: "high",
},
apns: {
payload: {
aps: {
contentAvailable: true,
},
},
headers: {
"apns-push-type": "background",
"apns-priority": "5",
"apns-topic": "io.flutter.plugins.firebase.messaging", // bundle identifier
},
},
}
And here the code which handle messages. (I want to create a notification from the client not from the server)
const AndroidNotificationChannel channel = AndroidNotificationChannel(
'high_importance_channel',
'High Importance Notifications',
'This channel is used for important notifications.',
importance: Importance.max,
);
class BackgroundHandler {
static const IOSNotificationDetails iosNotificationDetails =
IOSNotificationDetails(subtitle: 'notification');
static final AndroidNotificationDetails androidNotificationDetails =
AndroidNotificationDetails(channel.id, channel.name, channel.description);
}
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
print('It works');
print(message);
FlutterLocalNotificationsPlugin().show(0, 'notification', 'new notification', NotificationDetails(android: BackgroundHandler.androidNotificationDetails,
iOS: BackgroundHandler.iosNotificationDetails));
NotificationManager.handleNotificationData(message.data);
});
On Android it works perfectly and it works even with notification, but nothing happens with data only messages.

onMessage is not called while data only message on ios

I am doing fcm integration to flutter demo application.onMessage method is not called when data only message is sent through postman in any condition(forground,background,killed.) (ios physical device iphone5s).
I have tried notification +data message it is working properly. as described in firebase_messaging plugin.
{
"to" :"firebase-token",
"data" : {
"click_action": "FLUTTER_NOTIFICATION_CLICK",
"body" : {
"message":"this is data message"
},
"title" : "data title",
"content_available" : true,
"priority" : "high"
}
}
here is content of notification request of postman
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
Fimber.d("onMessage: $message");
Fluttertoast.showToast(msg: "onMessage: $message",
toastLength: Toast.LENGTH_LONG
);
},
onLaunch: (Map<String, dynamic> message) async {
Fimber.d("onLaunch: $message");
Fluttertoast.showToast(msg: "onLaunch: $message",
toastLength: Toast.LENGTH_LONG
);
},
onResume: (Map<String, dynamic> message) async {
Fimber.d("onResume: $message");
Fluttertoast.showToast(msg: "onResume: $message",
toastLength: Toast.LENGTH_LONG
);
},
);
_firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(sound: true, badge: true, alert: true));
_firebaseMessaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings) {
Fimber.d("Settings registered: $settings");
});
_firebaseMessaging.getToken().then((String token) {
Fimber.d("token: $token");
});
it is in init state of homepage.
i have permission notifications in ios and working well with notification+data.
-result should be as described in https://pub.dartlang.org/packages/firebase_messaging#-readme-tab-
-i have found work around from here
add notification and sound to json like this
{
"content_available" : true,
"priority" : "high",
"to" :"fcm-token",
"notification":{
"sound": ""
},
"data" : {
"click_action": "FLUTTER_NOTIFICATION_CLICK",
"body" : {
"message":"3:57pm"
},
"title" : "data title",
"content_available" : true,
"priority" : "normal"
}
}

FCM Notification in iOS doesn't play sound when received

I am using Firebase push notifications in my iOS Application. Although I am able to send the notification by sending below payload, it doesn't play a sound when received.
{
"to": "myToken",
"notification": {
"body": "test",
"title": "test"
},
"priority": "high"
"sound": "default"
}
If I send the test message from console, it works well and plays notification sound. Note:
My Authorization code is correct
I am sending http request to https://fcm.googleapis.com/fcm/send
I have tested it on IPhone 4 , IPhone 6 and IPhone 6S, All recieve
notifications without sound
your JSON "sound" : "default" should be inside the "notification" key not in the root of the JSON. This JSON should work.
{
"to": "myToken",
"notification": {
"body": "test",
"title": "test",
"sound": "default"
},
"priority": "high"
}
When using the FCM admin SDK, you have to specify sounds separately for Android and Apple devices:
let message = {
notification: {
'body': 'This is the message the user sees',
},
data: {
'param1': 'specify some extra data here',
},
// Apple specific settings
apns: {
headers: {
'apns-priority': '10',
},
payload: {
aps: {
sound: 'default',
}
},
},
android: {
priority: 'high',
notification: {
sound: 'default',
}
},
token: 'target FCM token goes here',
};
(Note: I've only tested the Apple settings thus far)
payload = {
notification:{
title: 'SOLO has been changed by an administrator',
body: 'Administrator changed your SOLO schedule',
},
android: {
},
apns: {
headers:{
"apns-collapse-id": "solo_changed_administrator",
"content-available": "1",
"apns-priority": "10",
},
payload:{
aps:{
sound: 'default',
badge: 12213123223
}
}
},
data:{
type: 'type'
}
}
https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0#ApnsConfig
I had the same problem. When notifications come through FCM to iOS not working sounds or vibrations. Here I followed this link: https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html#//apple_ref/doc/uid/TP40008194-CH17-SW1
And finally went successful. I created my apple notification as an alert in my payload and it works for me. Here is my JSON below to get some idea about my solution.
"apns": {
"payload": {
"aps" : {
"alert" : {
"body": "Notification body",
"title": "Notification title"
},
"badge" : 2,
"sound" : "default"
}
}
}
Note: Please put this "apns" key in the relevant place of your message request. I was using REST call for requesting message.
Please refer the following link to get a good idea of how to send a notification message with platform-specific delivery options.
Link: https://firebase.google.com/docs/cloud-messaging/concept-options#example-notification-message-with-platform-specific-delivery-options

Firebase Cloud Messing possible bug?

I am trying to send a push notification through FCM, but the response sent to the phone is weird and does not include aps.
I send:
{ "notification" : {
"title" : "this is title",
"body" : "this is body",
"sound" : "defadult"
},
"data": {
"score": "5x1",
"time": "15:10"
},
"time_to_live" : 3000,
"priority" : "high",
"content_available": true,
"to" : "<fcm access token>"
}
and I get the following on the phone:
%# [notification: {
body = "this is body";
e = 1;
sound = default;
sound2 = defadult;
title = "this is title";
}, collapse_key: <bundle-url>, score: 5x1, time: 15:10, from: 844316448558]
This had been working for a while but suddenly broke. Does anyone else experience this?

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