iOS Firebase Cloud Messaging Push Notifications using Ionic 4 not working - ios

I am developing a cross-platform application, which requires the use of Push Notifications for both Android and iOS. I am currently using the latest Cordova plugin I've discovered for firebase-cloud messaging: https://www.npmjs.com/package/cordova-plugin-fcm-with-dependecy-updated, which works flawlessly for Android but does not improve my situation with iOS.
I've also done the following:
Check Xcode console if the connection to FCM is successful
Check if subscription to the desired topic is successful
Added com.google.fcm to Url Types in Xcode
Readded both Push Notifications and Background Mode (Remote Notifications) in Capabilities in XCode
I have the following code to set up Push Notifications, which works for Android:
this.fcm.subscribeToTopic(`my-desired-topic`);
this.fcm.onNotification().subscribe(msg => {
if (this.platform.is("ios")) {
this.showAlert(msg.aps.title, msg.aps.alert, [
"/notifications",
id
]);
console.log(msg.aps);
} else {
this.showAlert(msg.title, msg.body, ["/notifications", this.eventId]);
console.log(msg);
}
if (msg.wasTapped) {
this.router.navigate(["/notifications", id]);
console.log("Received in background");
} else {
// this.router.navigate(["/notifications", id]);
console.log("Received in foreground");
}
});

Related

iPhone Device token not getting pushed to salesforce through SalesforceMobileSDK for CORDOVA

I am trying to implement Apple Push Notification through SalesforceMobileSDK for a Hybrid mobile app (IONIC, Cordova).
The problem is that the device token is not getting registered to Salesforce user. When I use the below-mentioned code suggested in the salesforce docs-
cordova.require("com.salesforce.util.push").registerPushNotificationHandler( function(message) {
// add code to handle notifications
},
function(error) {
// add code to handle errors
} );

Ionic Capacitor - Push Notification not making sound on iOS

We're using this guide to create a pretty routine push notification system.
We have everything working and push notifications are coming through. On Android, the push notifications make the default alert sound. On iOS however, no sound is made.
How can we configure the push notification to use the default alert sound on iOS (we don't want to create/manage a custom alert sound).
I've already configured the presentationOptions setting in the capacitor.config.json file.
{
"appId": "REDACTED",
"appName": "REDACTED",
"bundledWebRuntime": false,
"npmClient": "npm",
"webDir": "www",
"plugins": {
"PushNotifications": {
"presentationOptions": ["badge", "sound", "alert"]
}
}
}
Push notifications appearance in foreground
On iOS you can configure the way the push notifications are displayed when the app is in foreground by providing the presentationOptions in your capacitor.config.json as an Array of Strings you can combine.
Possible values are:
badge: badge count on the app icon is updated (default value)
sound: the device will ring/vibrate when the push notification is received
alert: the push notification is displayed in a native dialog
An empty Array can be provided if none of the previous options are desired. pushNotificationReceived event will still be fired with the push notification information.
"plugins": {
"PushNotifications": {
"presentationOptions": ["badge", "sound", "alert"]
}
}
push-notifications-appearance-in-foreground
What are you using to send the push notification?
I followed the same capacitor guide and faced the same issue, then I did a test by sending the notification from the Firebase Cloud Messaging console and it worked on iOS (the notification made a sound).
I found later that in the code I was using to send the notification (the firebase nodejs admin SDK), I didn't provide a value for the sound attribute. I assumed that since it's not required and it worked on Android, it should also work on iOS. I was wrong!
import * as admin from 'firebase-admin';
const message: admin.messaging.MessagingPayload = {
data: {
...
},
notification: {
title: 'title',
body: 'body',
sound: 'default' // Add this line
},
};
await admin.messaging().sendToDevice(tokens, message);
The docs says that this attribute is only for the Android platform, which is why I didn't set it at first.
PS: I also added the presentationOptions setting mentioned above in the capacitor.config.json file.

iOS ionic application doesn't receive FCM silent notifications

I have an Ionic 3 application which uses FCM for chat functionality. To handle FCM messaging I use cordova-plugin-fcm.
In my application I use only silent mode (without "notification" payload).
It works fine on Android. In iOS I received messages only if it sent with both "data" and "notification" payloads. If I try to use silent mode , messages aren't delivered at all.
For iOS I use FCM, not APN.
I send FCM messages as in the example of cordova-plugin-fcm.
{
"data":{
"param1":"value1",
"param2":"value2"
},
"to":"/topics/topicExample",
"priority":"high",
}
This stuff works differently on Android and iOS. You need to define the ios-specific apns.payload.aps object within the notification.
apns: {
payload: {
"aps" : {
"content-available" : 1
},
"acme1" : "bar",
"acme2" : 42
}
}
You also need to allow remote background notifications in your plist. If you're using Xcode (the easiest),
In the Project Navigator, select your project.
In the editor, select your iOS app target.
Select the Capabilities tab.
Enable the Background Modes capability.
Enable the Remote notifications background mode.
Source: https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW1

Ionic 2 - Show notification when app is in foreground on IOS

I am making a chat application in Ionic 2. I want notifications to appear even when app is in foreground. I have tried using Phonegap Plugin Push and FCM Plugin both and I'm getting notifications when app is in background and when app is killed.
But these plugins didn't show notifications when app is in foreground. So I used Local Notifications Plugin by Katzer. It works for Android perfectly but in IOS I'm facing multiple issues.
When used with Phonegap Plugin Push, the local notification does appear but its click event does not work. Also, the two plugins seem to have some conflicts so when used together, sometimes normal push notifications does not arrive or their click events does not work.
When used with FCM plugin, no local notification arrived.
I also tried using phonegap-plugin-local-notification but again it worked for Android but in IOS, notification arrives in form of alert and also its click event gets called automatically.
I am stuck on this for a long time. Can someone please provide a solution? All I want is to get notification in the notification center when app is in foreground in IOS and also a click event so I can do redirection on click.
Any help would be appreciated.
I was implementing in my cordova app this plugin.
And when device ready I fired this code:
pushNotification.register(
function (result) {
//Do some stuff
}, function (error) {
//Do some stuff on error
}, {
"badge":"true",
"sound":"true",
"alert":"true",
"ecb": "onNotificationAPN"
});
And also implemented below function:
function onNotificationAPN(event) {
if (event) {
if ( event.alert ) {
alert(Recieved alert: + event.alert);
}
if ( event.sound ) {
var snd = new Media(event.sound);
snd.play();
}
if ( event.badge ) {
pushNotification.setApplicationIconBadgeNumber(function() {
//SetApplicationIconBadgeNumber success.
}, function() {
//SetApplicationIconBadgeNumber error.
},
event.badge);
}
}
}
And I am able to receive notifications also in foreground.

My distributed app doesn't ask if user want to subscribe to push notifications

I am developing an app for iOS using Titanium API (SDK 5.0).
This app provides a push notification service, which is successfully tested on dev device.
After publishing with the distribution profile, I realized my app have not asked to users if they accepted the push notifications for this app.
Notice that all devices are on iOS 4.3 or more, I updated my provisioning and distribution profile, I checked certificates for this app, including push notification service.
Here my code for registration:
Titanium.Network.registerForPushNotifications({
types: [
Titanium.Network.NOTIFICATION_TYPE_BADGE,
Titanium.Network.NOTIFICATION_TYPE_ALERT,
Titanium.Network.NOTIFICATION_TYPE_SOUND
],
success:function(e)
{
//get the device token then send it to server
var deviceToken = e.deviceToken;
stockToken(token)
},
error:function(e)
{
return;
},
callback:function(e)
{
//when receive a notification
winAutres.message_push=e.data.alert;
tabGroup.setActiveTab(4);
return;
}
});

Resources