Reinstalling the phonegap app causes unable to receive push notifications while app is running - iphone

I am creating an app using Phonegap 3.1, Sencha 2.3 for the platform android and iPhone.
For sending notification, i have used pushwoosh service and followed this link (http://www.pushwoosh.com/programming-push-notification/ios/ios-configuration-guide/)
Notification are getting perfectly on both Android and iPhone devices (whether app is running or not).
But the problem is, when I reinstall the app, i am not able to get notifications when the app is running and notifications are getting when app is minimized or not running.
In my index.html file, I have used this code to receive the notification while app is running.
document.addEventListener('push-notification', function(event) {
alert('push-notification');
var notification = event.notification;
navigator.notification.vibrate(1500);
navigator.notification.confirm(
notification.aps.alert, // message
alertDismissed, // callback
'ThisApp', // title
'Done' // buttonName
);
pushNotification.setApplicationIconBadgeNumber(0);
});
function alertDismissed() {
//do something after Done button pressed
}
After reinstall the app this listener is not calling.
I am not getting what actually missing in there, please advise.

Related

flutter_callkit_incoming notification isn't received in terminated or background state in iOS using Flutter

Flutter Incoming Callkit notifications are working fine on my iOS app in all states (foreground/background/terminated).
On iOS device, issue is when my app is in background or terminated state and if I open any other app after closing or minimizing my application , I stop getting callKit notification in both background/terminated state.
I don't know that which part can cause this issue i.e if its from my code or its the problem in iOS device itself. Because besides opening another app after closing/minimizing my app, I am getting call notifications in all states of my app.
[Note: Everything is working fine in the Android app]
This is the silent notification being received to the receiver from cloud function.
await admin.messaging().send({
token: token_o,
notification: {
},
data: {
imageUrl: requesterImageUrl,
chatRoomId: chatRoomId,
screenName: 'voiceScreen',
voiceCall: 'voiceCall',
callerName: requesterName,
callsDocId: callsDocId,
senderId: requesterId,
},
android: {
notification: {
click_action: "android.intent.action.MAIN"
},
},
apns: {
headers: {
apns_priority: "10",
},
payload: {
aps: {
badge: 1
},
notification: {
title: "iOVoiceCallNotification",
body: {},
},
mutable_content: true,
content_available : true,
}
}
}).then(value => {
functions.logger.log("Notification for AudioCall is sent to the Receiver");
}).catch((e) => {
functions.logger.log(e.toString());
});
I can provide anyother code or log if required.
I simply had to configure pushKit to awake iOS from background & terminated state.
Note: Even for pushKit, I had to create a token for iOS device from the getVoipToken() function that is present in flutter_call_kit incoming package.
Inorder to recieve callKit notifications perfectly in background/terminated states in IOS you have to do following necessary things:
Implement APNs (Apple push notifications) for IOS. Because IOS devices will not wake the phone and show call when you send firebase notifications in background/terminated states. IOS devices require APNs to achieve this.
Follow the instructions written in PUSHKIT.md if you are using flutter_callkit_incoming package for flutter app.
Configure your backend (from where you want to recieve notifications) to send both firebase and APN notifications depends upon the device user is using. (I recommend you to send the platform e.g "android" or "ios" along with the device token to your backend when you register the firebase token in flutter app. You can also ask for IOS deviceToken from firebase.
I know its very lengthy process but it is. I was also very disappointed when I was required to integrate call notifications in my app and I have to do all this on my frontend app and backend.

Flutter firebase messaging v9.0.0 - Not firing events

I have an app that was using firebase messaging 7.0.3 and all worked perfectly. But when I migrated to firebase messaging 9.0.0, the push notifications are not being handled.
I know that the app is correctly linked to firebase and cloud messaging because in background I see the push notification comming, the problem is when I click that notification the app don't handle this event. Also, when the app is in foreground, the event of receiving the notification is not being triggered.
Specifically, the functions FirebaseMessaging.onMessage and FirebaseMessaging.onMessageOpenedApp are not working. My code is:
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
print("notification: message");
});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
print("notification: resume");
});
The prints are never called, and if I put some more code inside isn't executed too.
I also call FirebaseMessaging.getToken and I can get the token, plus when the app is in background I get the push notification, so is not a link problem with firebase. In the logs, when I receive the push I can see a message saying: Broadcast received for message. So I assumed that the push is arriving in all the occasions, and I am doing something wrong in the code.
I tested all cases in Android and iOS physical devices.
Someone know why this occurs?
I came across this exact same issue after migrating and upgrading to 9.0.0.
There is a minor issue with 9.0.0 plugin.
The fix can be found here:
https://github.com/FirebaseExtended/flutterfire/issues/4949
To cut a long story short, if you navigate to the definition of the factory
RemoteMessage.fromMap() Using Cmd+Click or Ctrl+Click while hovering over the RemoteMessage class with the mouse), in the return statement, change contentAvailable: map['contentAvailable'], to contentAvailable: map['contentAvailable']??false.
Notifications are now working for me again now.
This should work for you until the plugin is fixed.

(Ionic) handleNotificationReceived does not get called if the app is killed

I am working on an ionic app and I am using onesignal for push notifications.
The problem I am facing is that the handleNotifiactionRecieved() does not get triggered upon receiving a push notification when the app is not killed (that is removed from the recent apps). Though it works as expected when the app's running but in the background(not inFocus).
setup code is something like this:
if (this.platform.is('cordova')) {
this.oneSignal.startInit('APP_ID');
this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.None);
this.openOneSignalMessage();
this.oneSignal.endInit();
}
my code is something like this:
openOneSignalMessage() {
this.oneSignal.handleNotificationReceived().subscribe((data) => {
this.MsgBody = data.payload.body
console.log('newMessageOneSignal MsgBody', this.MsgBody);
});
}
actual result: handleNotificationReceived() doesn't get called when the app is not running, that is killed.
expected result: handleNotificationReceived() should be called every time a push notification arrives even when the app is not open.
How do I trigger the method every time?
Thanks in advance.
Thanks for pointing out the issue in the docs. They have been updated with the correct info:
handleNotificationReceived (builder method)
Sets a notification received handler. Only called if the app is running in the foreground at the time the notification was received.
If you want to handle from a killed state, make sure to use the handleNotificationOpened method
I find this in the doc:
Sets a notification received handler. Only called if the app is running in the foreground or background at the time the notification was received.
Maybe your app is not working on background.
Or the problem is you need to call ur function after the startinit :
this.onesignal.startInit("YOUR_APPID")
this.onesignal.handleNotificationReceived()

Background notifications using Ionic like a mortal

I have been trying for several months to implement an app that receives notifications whose content I want to be stored in the database of my application. I am using the Firebase Messagging plugin and I am receiving the notifications correctly, both in Foreground and in Background.
However, in the background I am unable to execute my callback without the need to press the notification explicitly by the user. Likewise, there is no way to increase the badge of the application when it is not open.
Now, I do not understand how applications like WhatsApp, Telegram and any other application that is not made by mere mortals work. How is it possible that they can get the data in backgroud, manage the badges, synchronize messages, etc? Being that, supposedly the services like Firebase are limited in background. Even with plugins like Background Mode my application is suspended by Android when the user closes it.
The code that I am currently using to handle notifications is the following:
// In foreground (WORKS)
this.firebaseMessaging.onMessage().subscribe((notificacion) => {
// Insert in DB
...
});
// In background (DOESN'T WORK)
this.firebaseMessaging.onBackgroundMessage().subscribe((notificacion) => {
// Insert in DB
...
});
What alternative is left? The only thing that occurs to me is to use notifications in Foreground and background only as a warning. So every time I open the application I'll have to call a message synchronization callback with the server (with badge management included).
If someone has some better way, I would greatly appreciate it if you throw a little light on the subject.
From already thank you very much
Ok, after more than a year I think it's time to close this question. I solved the problem this way:
Suppose I need to get a list of messages. This action is made by a function called getMessages()
When a new message is created in the backend, I send a push notification through Firebase service.
If the push notification is received in foreground I refresh call the method directly:
this.firebaseMessaging.onMessage().subscribe((notificacion) => {
getMessages();
});
If the push notification is received in background and the user taps on it there isn't a problem as it's supported by the plugin:
this.firebaseMessaging.onBackgroundMessage().subscribe((notificacion) => {
getMessages();
});
If the push notification is received in background but the user DOES NOT tap on it and opens the app in another way than the notification, we need to excecute the corresponing function when the app is opened in app.component.ts file:
this.platform.ready().then(() => {
getMessages();
// Extra stuff like this.statusBar.styleDefault(); or this.splashScreen.hide();
});
That way all the cases are considered! You should keep in mind that apps like Whatsapp or Telegram are developed in official technologies like Java or Kotlin which not only have official native plugins, also its code are excecuted natively and not in a limited browser as Cordova or Capacitor frameworks do

canShareVia invokes the success callback when it should not - iOS 11.2

Description
When the Facebook app is not installed, canShareVia method should invoke the error callback, which is working perfectly with my iPhone5s running iOS 10.
When I test it on iPhone5s running iOS 11.2, it is always invoking the success callback in both the cases where the Facebook app is installed and Not installed.
App
A Cordova mobile app
Plugin: https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin
Device information
iPhone 5s
iOS 11.2
Facebook app: Not installed
Sample code
window.plugins.socialsharing.canShareVia('com.apple.social.facebook', 'msg', null, null, null,
function(success) {
do some stuff....
}, function(error) {
alert(error);
});
Please let me know if any work around has been found.
Updated
Found the cause:
This plugin always returns true since iOS11. So we might need another way to detect if there is an app installed and available.
Get it to work with cordova-plugin-appavailability.
You can implement this way (Appavailability plugin to check Facebook app availability and social sharing plugin to do the actual sharing).
appAvailability.check(
'fb://',
function() { // Success callback
window.plugins.socialsharing.shareViaFacebook(...)
},
function() { // Error callback
console.log('Facebook App is not available');
}
);
Though this is a work around but not a fix, this is the only way for now until the fix gets merged to cordova-plugin-x-socialsharing.
You can find the answer for your question here.
App Availability.
Read this and your requirement will be piece of cake.