flutter_callkit_incoming notification isn't received in terminated or background state in iOS using Flutter - 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.

Related

How to add device for push notification service GetStreamApi

I am using the getstream api and I would like to enable push notification services on both android and ios devices. The documentation just shows various excerpts on various parts of the process and I don't understand why. This is a nuanced topic and detailed step by step process should be the standard.
But essentially, I am not sure how to add a device to a client.
I have tried the below (which i'm not sure is the right way to go about it, but the documentation is not clear) but I get an unauthorized token error:
_invokeGetStreamApiFcmToken() async {
final client = StreamChatCore.of(context).client;
//listen for fcm token refresh
FirebaseMessaging.instance.onTokenRefresh.listen((token) {
client.addDevice(token, PushProvider.firebase);
print("get stream api token refreshed -- $token");
});
print(await FirebaseMessaging.instance.getToken());
print(await FirebaseMessaging.instance.getAPNSToken());
// register the device with APN (Apple only)
await client.addDevice(uid, PushProvider.apn);
// register the device with Firebase (Android only)
await client.addDevice(uid, PushProvider.firebase);
print(await client.getDevices());
}
In the client.addDevice() method, I am not sure at all what the first parameter, "device id" is meant to be. How do i get this device ID?

Huawei PushKit Notifications doesn't appear when app is killed or in background

I have integrated the Huawei Push kit to my app and when I trigger a notification from Huawei Push Kit Console, I can receive the notification when the app is in background. However, when our system backend triggers Huawei API to push notifications, it doesn't appear when the app is in the background.
Following code is getting executed despite the app is in foreground or background but Notification parameters such as Title etc, coming as null. Notification object itself is not null.
Contents of the JSON message can be received as a single String from remoteMessage.getData() but values does not mapped to respective fields.
public class HuaweiNotificationHandler extends HmsMessageService{
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.i(TAG, "getData: " + remoteMessage.getData()
RemoteMessage.Notification notification = remoteMessage.getNotification();
if (notification != null) {
Log.i(TAG, "getTitle: " + notification.getTitle()
}
}
}
Our backend executes this API provided by Huawei to send data messages.
This is the format of our JSON
{
"collapseKey":"dummykey",
"priority":"high",
"delayWhileIdle":false,
"dryRun":false,
"sound":"",
"contentAvailable":true,
"data":{
"data":{
"type":"A",
"id":"1111111",
"entity":"0",
"url":""
},
"restrictedPackageName":"com.aa.bb.cc" // this package name is exactly same as the huawei app package registered
},
"notification":{
"title":"Notification Title",
"icon":"ic_launcher",
"body":"Message"
}
}
UPDATE
Sample code of a typical data message:
{
"validate_only": false,
"message": {
"data": "{'param1':'value1','param2':'value2'}",
"token": [
"pushtoken1",
"pushtoken2"
]
}
}
For Details,see Docs.
Push Kit supports two types of messages: notification messages and data messages.
After a device receives a data message, the device transfers it to your app instead of directly displaying the message. Your app then parses the message and triggers the corresponding action. Push Kit only functions as a channel, and the delivery of data messages depends on the resident status of your app. However, notification messages can still be delivered even if your app is not launched.
For the sake of saving power and not disturbing users, your app will not be launched by Push Kit after being stopped, and no data messages can be delivered to your app. In this case, you can determine whether to use notification messages based on your services.
From: https://stackoverflow.com/a/64100678/14006527
Alternatively, you can set High-priority data messages to forcibly launch your stopped app to receive and process the messages.

Is there way to use push notifications in our ionic 4 project?

We currently have an Ionic and Firebase project that we coded. In this project, we want to use push notifications. But our trouble is:
We are looking for a push notification plugin, like WhatsApp application. For example, when we send a message to a person, we want the notification to go to the person we're texting from, not everyone. But we couldn't find a free way to do that. Do you have any suggestions? Thank you.
Firebase Cloud Messaging By using cordova-plugin and ionic-native:Ref. Url
import { FCM } from '#ionic-native/fcm/ngx';
constructor(private fcm: FCM) {}
this.fcm.getToken().then(token => {
//you can store device token in firebase, later you can target push notification from firebase console this token id
backend.registerToken(token);
});
this.fcm.onNotification().subscribe(data => {
if(data.wasTapped){ / * true , means the user tapped the notification from the notification tray and that’s how he opened the app. */
console.log("Received in background");
} else {// false , means that the app was in the foreground (meaning the user was inside the app at that moment)
console.log("Received in foreground");
};
});
this.fcm.onTokenRefresh().subscribe(token => {
//update device token
backend.registerToken(token);
});
I don't recommend you to use FCM plugin. It has no methods to manage your notifications in your app (clear all or clear some special notification.
It is better to use phonegap-push-plugin or One Signal

Implement Push notification in Android Phonegap app

Created UI using Angular and Ionic, and wrapper usign Phonegap, How can I have pushnotification in Android implemented.
Is there any effective and accurate library in Phonegap for Pushnotification Implemented.
Already using https://github.com/phonegap-build/PushPlugin, but getting some issues, like push notififcation not received, some time all notification coming at once.
First create a project in Google console
Enable GCM
Create a server api Key
use the following plugin
cordova plugin add phonegap-plugin-push --variable SENDER_ID="XXXXXXX"
replace the xxxxxx with your sender id
n your javascript add the following code for registering to GCM server it will give you a GCM id
var push = PushNotification.init({
android: {
senderID: "XXXXXXXX" //add your sender id here
},
ios: {
alert: "true",
badge: "true",
sound: "true"
},
windows: {}
});
push.on('registration', function(data) {
consol.log(data.registrationId); //this function give registration id from the GCM server if you dont want to see it please comment it
document.getElementById("gcm_id").value= data.registrationId; //showing registration id in our app. If it shows our registration process is suscess
//$("#gcm_id").val(data.registrationId); if you are using jquery
});
Send a message using GCM HTTP connection server protocol:
https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=YOUR SERVER KEY
{
"to": "GCM ID",
"data": {
"message": "This is a GCM Topic Message!",
}
}
for more details..
http://phonegaptut.com/2016/05/31/how-to-send-push-notifications-in-phonegap-application/
I was having the same problem lately, using Ionic and Cordova (not Phonegap, but should work the same).
I ended up using this library for local push notifications https://github.com/Wizcorp/phonegap-plugin-localNotifications
They worked pretty well except the PN would not start the app on Android, but I opened a pull request with a fix for that.
If you encounter the same problem, you might also use my fork of this plugin which has this fix already included.
You should be using ngCordova's Push Plugin for this.
From the docs:
Allows your application to receive push notifications. To receive notifications in your controllers or services, listen for pushNotificationReceived event.
As Push Notification is a native feature, so to integrate Push in PhoneGap Android application you have to make a plugin that will communicate with Android Native code.
You can go through with Sample application available on Git Hub.
Please also follow the necessary steps require for it mentioned in ReadME file.

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

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.