React Native PushNotification IOS can receive push message but without sound - ios

I encountered a problem with PushNotificationIOS using React Native. After I updated RN from 0.48 to 0.54 and upgraded my iPhone with iOS 11.3, my iOS app can receive push message but without sound. The notification part of the code was left untouched and there was no problem with message sound. Just wonder what configuration might need to be made to make the message sound normal. Thanks for your suggestions.
I check the notification object in debugging mode and it got alert title, body, and should value and looks good.
componentWillMount() {
PushNotificationIOS.addEventListener("register", this._onRegistered);
PushNotificationIOS.addEventListener(
"registrationError",
this._onRegistrationError
);
PushNotificationIOS.addEventListener(
"notification",
this._onRemoteNotification
);
PushNotificationIOS.addEventListener(
"localNotification",
this._onLocalNotification
);
}
....
_onRegistered(deviceToken) {
if (deviceToken)
...
console.log("Registered deviceToken=" + deviceToken);
}
_onRemoteNotification(notification) {
notification.finish(PushNotificationIOS.FetchResult.NoData);
var body = notification.getMessage().body.split("|");
if (body.length === 1)
Warn(
notification.getMessage().title, //message only.
body[0],
[{ text: "OK", onPress: null }]
);
else if (body.length === 2) {
//code + message
Warn(notification.getMessage().title, body[0] + "\n" + body[1], [
{ text: "OK", onPress: null }
]);
store.dispatch(sessionActionCreators.updateConfirmCode(body[0]));
}
}

How to make sound when notification came if application is active in ios?
Just found out that forcing to play the sound event if the app is at foreground is possible. Just call the API to play the sound/do vibration.

Related

Flutter: The notification badge counter on the iOS app icon on the home screen is not showing up (using FCM)

I am subscribing to a topic and pushing notifications using Firebase console/cloud messaging; On Android, everything works fine. On iOS, I receive notifications in the notification centre while the app is in foreground/background/terminated(profile mode)
PROBLEM : No badge appears on the iOS app icon.
I have been checking different articles and QAs but still no solution. Any clue or idea that can help me to do more investigation might solve it is appreciated.
Have tried > Running on both debug and profile mode, using iPhone 12 pro with iOS 15 & iPhone Xs
I have also tried flutter_app_badger still not getting any badge count.
in my main file;
Future<void> _messageHandler(RemoteMessage message) async {
print('background message ${message.notification!.body}');
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
).then((value) {
FirebaseMessaging.onBackgroundMessage(_messageHandler);
});
runApp(MyApp());
}
In the initState of my app's first screen;
#override
void initState() {
super.initState();
PushNotify().init(context);
messaging = FirebaseMessaging.instance;
messaging.subscribeToTopic("messaging");
messaging.setForegroundNotificationPresentationOptions(
alert: true, // Required to display a heads up notification
badge: true,
sound: true,
);
if (Platform.isIOS) {
messaging.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
}
FirebaseMessaging.onMessage.listen((RemoteMessage event) {
// FlutterAppBadger.updateBadgeCount(1);
if (event.notification != null) {
print('Message also contained a notification: ${event.notification}');
}
});
FirebaseMessaging.onMessageOpenedApp.listen((message) {
print('Message clicked!');
// FlutterAppBadger.removeBadge();
});
}
I struggled with this problem myself the past month.
I came to a realisation that the only way you're going to be able to show a badge ( on iOS ) when the notification is delivered is if you're sending that message from a custom-server and not the Firebase console.
The key issue here is the payload used to send the notification. You have to explicitly include a badge count in your payload for it to be shown on the iOS app icon.
If you're familiar with Typescript or Javascript, sending the message using this payload will show the given badge on the iOS app icon ( for messages sent when the app is in the background or terminated )
const createTokenPayload = (
token: string,
title: string,
message: string,
id?: string,
badge?: number
): TokenMessage => {
const payload: TokenMessage = {
token: token,
notification: {
title: title,
body: message,
},
apns: {
payload: {
aps: {
contentAvailable: true,
badge: badge, // this one here
},
},
},
android: {
priority: "high",
},
};
return payload;
};
That is for a notification sent to a single token.
I could not find a way to add badges when I wanted to send to all users subscribing to a topic. I thought the reason behind is; sending badges with the same value for all users subscribed to a topic irrespective of their current badge-counts is not good.
So the solution I am suggesting for this problem is sending individual notifications with the same message but different badges depending on the current value of the badge for each user.
I hope this helps.

React Native : messaging().onMessage is not triggered very first time app launched in iOS

I want to handle foreground firebase messages.
But messaging().onMessage is not triggered very first time app launched in iOS. This is working fine in Android.
Exact scenario is:
First time launch app : messaging().onMessage not triggered in iOS
Close and reopen app : messaging().onMessage will trigger
import { Alert } from 'react-native';
import messaging from '#react-native-firebase/messaging';
function FCMReadInForeGround() {
useEffect(() => {
const unsubscribe = messaging().onMessage(async remoteMessage => {
Alert.alert('A new FCM message arrived!', JSON.stringify(remoteMessage));
});
return unsubscribe;
}, []);
}
export default FCMReadInForeGround;```
i hope this help you. i have same problem, and the im looking documentation ios messaging setup.
here the link : https://rnfirebase.io/messaging/usage/ios-setup .
in my case I haven't Linking APNs with FCM (iOS)
Try calling setBackgroundMessageHandler outside your component.
// Register background handler
messaging().setBackgroundMessageHandler(async remoteMessage => {
try {
console.log('Remote notification', remoteMessage)
} catch (err) { console.log(err) }
});

IOS 13 doesn't play a notification sound using FirebasePushNotificationPlugin

I use Firebase to push notifications to the users at a certain time. They receive the notification but no alert sound is played. In the settings, the allow sound/notifications are turned on and other IOS13 and other apps play sound.
Version Number of FirebasePushNotificationPlugin Plugin: 3.3.10
Device Tested On: iphone X, OS: 13.4.1
Simulator Tested On: N/A (simulators don't receive notifications)
Version of VS: VS for Mac Community, 8.6.6 (build 11)
Version of Xamarin: Xamarin.IOS 13.18.2.1, Xamarin.Forms v4.6.0.847
AppDelegate.cs:
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
bool fbaseStarted = false;
try
{
// This method does all the UNUserNotificationCenter.Current.RequestAuthorization() code so we don't have to.
FirebasePushNotificationManager.Initialize(options, true);
fbaseStarted = true;
}
catch
{ }
LoadApplication(new App());
if (!fbaseStarted)
{
try
{
FirebasePushNotificationManager.Initialize(options, true);
}
catch { }
}
FirebasePushNotificationManager.CurrentNotificationPresentationOption = UNNotificationPresentationOptions.Badge | UNNotificationPresentationOptions.Alert | UNNotificationPresentationOptions.Sound;
}
Within one of the pages of my code, I subscribe a list of tags (please note that I unsubscribe because the first time the code runs it fails silently if the notifications aren't approved - resulting in the model thinking the notifications was subscribed when it wasn't):
CrossFirebasePushNotification.Current.UnsubscribeAll();
CrossFirebasePushNotification.Current.Subscribe(Constants.NotificationTagsArray);
I keep coming across payload json solutions but unless I am wrong, I don't think that applies to me as I am using Xamarin and the FirebasePushNotificationPlugin. Is there any additional permissions that were added in ios 13 for playing notifications with sound that I have missed?
I have also posted here: https://github.com/CrossGeeks/FirebasePushNotificationPlugin/issues/348 but nobody has been able to assist me yet.
Thanks
The issue actually lies with the sending of the notifications nothing to do with the Xamarin App. The issue resided in the services that sends the notifications to firebase (to then be sent out to the phones).
In the service we were sending a FirebaseNet.Messaging.Message() to the phones:
Message FireBasemessage = new Message()
{
To = "/topics/" + PushNote.Tag,
TimeToLive = 86400,
Priority = MessagePriority.high,
ContentAvailable = true,
Notification = new AndroidNotification()
{
Tag = "/topics/" + PushNote.Tag,
Body = enhancedMessage,
Title = xtitle,
}
,
Data = new Dictionary<string, string>
{
{ "param", PushNote.Tag },
{ "text", enhancedMessage}
}
};
In the AndroidNotification() object required Sound = "default" to be added for it to work. Please note that this works for both Android and IOS notifications despite the fact it is an AndroidNotification object.

React-native-firebase Bigimage not working in ios

i can not show big image in notification in ios when app close or open , but working in android
var display_notification = new firebase.notifications.Notification({
show_in_foreground: true
})
.setNotificationId(notification._notificationId)
.setTitle(notification._title)
.setBody(notification._body)
.setData(notification._data);
if (Platform.OS == "android") {
display_notification.android
.setChannelId("fcm_default_channel")
.android.setSmallIcon("ic_notification")
.android.setBigPicture(notification._data.picture)
.android.setColor("#171551");
} else {
display_notification.ios.addAttachment(
"1",
"https://files.allaboutbirds.net/wp-content/uploads/2015/06/prow-featured.jpg"
);
}
show notification in ios but not display big-image (rich notification )
You can use IOSNotification
iOS specific notification settings.
NOTE: Some of these settings apply only to iOS 9, or iOS 10+.
These are flagged as appropriate.
launchImage returns nullable string;
Gets the launch image to use with the notification.
setLaunchImage(launchImage) returns Notification;
Sets the launch image for the notification.
launchImage : string
Example
notification
.ios.setLaunchImage('notificationimage.png');
Description of IOSNotification
Description of Displaying Notifications

Why I don't get any push notification on my ionic iOS app?

I am trying to implement push notifications in my app developed with Ionic 3. I am following this tutorial : https://medium.com/#ankushaggarwal/generate-apns-certificate-for-ios-push-notifications-85e4a917d522
Everything went well for Android, on which I get notifications.
But, on iOS, when I send a push notification, I get absolutely nothing on iOS.
I did the following :
get an APN push certificate
uploaded it in my Ionic account
switched "Push notifications" on under the "capabilities" tab in Xcode
also switched on "Background modes / Remote notifications" under the same tab
My code is the same as the one in the tutorial above :
initPushNotifications() {
if (!this.platform.is("cordova")) {
console.warn("Push notifications not initialized. Cordova is not available - Run in physical device");
return;
}
const options: PushOptions = {
android: {
senderID: "784098698049"
},
ios: {
alert: "true",
badge: false,
sound: "true"
},
windows: {}
};
const pushObject: PushObject = this.push.init(options);
pushObject
.on("registration")
.subscribe((data: any) => {
console.log("device token -> " + data.registrationId);
this.userService.edit({
ionicToken: data.registrationId
});
});
pushObject.on("notification").subscribe((data: any) => {
console.log("message -> " + data.message);
//if user using app and push notification comes
if (data.additionalData.foreground) {
// if application open, show popup
let confirmAlert = this.alertCtrl.create({
title: "New Notification",
message: data.message,
buttons: [{
text: 'Ignore',
role: 'cancel'
}, {
text: 'View',
handler: () => {
//TODO: Your logic here
}
}]
});
confirmAlert.present();
} else {
//if user NOT using app and push notification comes
//TODO: Your logic on click of push notification directly
console.log('Push notification clicked');
}
});
pushObject.on('error').subscribe(error => console.error('Error with Push plugin' + error));
}
I also tried following the official documentation at https://docs.ionic.io/services/push/, which doesn't use the same modules. Still, the result is the same : it works on Android but not on iOS.
I don't know if I can find some logs somewhere, to figure out if there is an error. If somebody has informations about this, please share.
Does anybody had any success on implementing push notifications with Ionic ?
Thanks.
You need to run your app either through Apple's testflight or App store. In my experience, push notifications don't work if you just run your app locally on you phone.

Resources