OneSignal does not showing notification when app is in foreground - push-notification

I entegrated my flutter app with onesignal, and it's working perfect when app is in background, but in foreground it's receiving notification but not showing it any idea why?
log
flutter: OSNotificationReceivedEvent complete with notification: Instance of 'OSNotification'
VERBOSE: finishProcessingNotification: Fired!
VERBOSE: Notification display type: 7
VERBOSE: notificationReceived called! opened: NO
VERBOSE: finishProcessingNotification: call completionHandler with options: 7
Foreground handler
OneSignal.shared.setNotificationWillShowInForegroundHandler(
(OSNotificationReceivedEvent event) {
event.complete(event.notification);
});

I've removed the answer because I think it is just copy paste

Related

FCM Admin Sent Notifications don't Open Links When Clicked

I'm trying to get our FCM Message notification on devices to open a URL when clicked on various devices. I've tried click_action and link in the various object configurations supplied with the target the URL string but nothing seems to work. Currently the object is defined as
const fcmMessage = {
data: {
time_to_live: (60 * 120).toString(),
notification: JSON.stringify({
title: `Title String`,
body: message_text,
link: `${process.env.FCM_ACTION_LINK}/user/messages?room_id=${message_room_id}`,
room_id: message_room_id
}),
},
};
I've tried changing where link is placed in the object definition outside of notification and also changing the keyname to click_action but nothing seems to get the URL to open when clicked in the received notification.

PWA listen for event upon receiving push notification (while app is not running)

I'm trying to get the data that i receive from my push notification and display it in the pwa. The idea is that i have a push notification coming in with a text body, then the user clicks on the push notification and the PWA opens up with the data from the push notification displayed on the section. I have managed to get it work when it is open as i placed it in the mounted lifecycle and the function activates when it listens to the message that comes in. The only problem is when the push notification comes in, the user will not be having the PWA all the way. So how do i overcome this? I have tried inserting in other lifecycle methods but it seems redundant since the PWA is not even opened yet when the push notification arrives. Hope anyone here can advise on this. Thank you very much.
mounted(){
navigator.serviceWorker.addEventListener('message', (e) => {
console.log('Push Notification received');
console.log(e.data.firebaseMessagingData.notification.body);
var timestamp = new Date().toLocaleTimeString(undefined, {hour: '2-digit', minute: '2-digit'});
const robotMessage = {
text: e.data.firebaseMessagingData.notification.body,
isRobot: true,
timestamp: timestamp
}
firebase
.firestore()
.collection("users")
.doc(firebase.auth().currentUser.uid)
.collection("messages")
.add({
robotMessage: robotMessage.text,
timestamp: robotMessage.timestamp
});
this.messages.push(robotMessage);
});
}

Custom click on Ionic notification using Firebase

I have been using ionic and FCM (Firebase Cloud Messaging) for notification.
I get the notification on my app and now I have 2 issues. First, if its a normal notification like not with advanced options in Firebase Console > Notification, then it doesn't play any sound, but when it's data Notification, then it does play a sound. Second, I want to open a particular page of my app on notification click.
So how do I do that?
Note: I am using ionic not an ionic2.
First issue:
We have sound in both situations. Have you tried to send an empty data object?
Second issue:
Just assuming you use the Cordova FCM plugin. Otherwise install it with
cordova plugin add cordova-plugin-fcm --save
Use the data with an ID to the right datapage and then do something like:
angular.module('app', ['ionic'])
.run(function ($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova) {
FCMPlugin.onNotification(
function(data){
if(data.wasTapped){
//Notification was received on device tray and tapped by the user.
$state.go('yourpage', {id:data.pageId});
console.log('onNotification tapped true');
} else {
//Notification was received in foreground. User needs to be notified.
console.log('onNotification tapped false');
}
},
function(msg){
console.log('onNotification callback successfully registered: ' + msg);
},
function(err){
console.log('Error registering onNotification callback: ' + err);
}
);
}
});
});

User based notifications with the Bluemix Push Notification service

Currently developing a Cordova app and wanted to use the IBM Bluemix Push Notification service to send user based push notifications.
According to the documentation here, seems like the first step is to call MFPPush.initialize(appGuid, clientSecret), which I tried to do. But this function is not present in the plugin interface and therefore I get an 'undefined' error when running the app.
Moreover, the doc also talks about calling MFPPush.registerDevice({},success,failure,userId). However, when I look at the plugin javascript interface, it only takes 3 parameters.
Could someone please give some advice to help me sort this out?
Thanks.
I just ran the Bluemix Cordova hellopush sample which should help you out. Make sure you follow the directions in the README, and make sure to change the route and guid in your index.js (it should look something like this):
route: "http://imfpush.ng.bluemix.net",
guid: "djkslk3j2-4974-4324-8e82-421c02ce847c",
You will be able to find the route and guid in your Push Notifications service credentials.
After running it by following the directions (and ensuring that you have GCM / APNS set up correctly for whatever platform you are using), you should be greeted with this screen after clicking register:
#johan #joe Cordova app can use the IBM Bluemix Push Notification service to send user based push notifications. Please follow the below example using BMSPush to register for Push Notifications.
// initialize BMSCore SDK
BMSClient.initialize("Your Push service region");
// initialize BMSPush SDK
var appGUID = "Your Push service appGUID";
var clientSecret = "Your Push service clientSecret";
// Initialize for normal push notifications
var options = {}
BMSPush.initialize(appGUID,clientSecret,options);
// Initialize for iOS actionable push notifications and custom deviceId
var options ={"categories":{
"Category_Name1":[
{
"IdentifierName":"IdentifierName_1",
"actionName":"actionName_1",
"IconName":"IconName_1"
},
{
"IdentifierName":"IdentifierName_2",
"actionName":"actionName_2",
"IconName":"IconName_2"
}
]},
"deviceId":"mydeviceId"
};
BMSPush.initialize(appGUID, clientSecret, options);
var success = function(response) { console.log("Success: " + response); };
var failure = function(response) { console.log("Error: " + response); };
// Register device for push notification without UserId
BMSPush.registerDevice(options, success, failure);
// Register device for push notification with UserId
var options = {"userId": "Your User Id value"};
BMSPush.registerDevice(options, success, failure);
Please go through the Bluemix Cordova Plugin Push SDK doc link.

push not initilizing when trying to create hybrid android application

I am trying to implement push notifications using bluemix and mobilefirst. I have used the following links to implement
http://www.ibm.com/developerworks/library/mo-cordova-push-app/
http://mbaas-gettingstarted.ng.bluemix.net/hybrid#initialize-push -
When i run the the below code I am getting the following message in the console:
initPush called----------------
main.js:29 calling bluemix initialize with values----------------------
IBMBluemixHybrid.js:2956 [INFO] [DEFAULT] Hybrid initialize ["applicationid","applicationsecret","applicationroute"]
I neither see the device details reflected in the bluemix registered list. Can you please help me on this ?
var values = {
applicationId:"applicationId",
applicationRoute:"applicationRoute",
applicationSecret:"applicationSecret"
};
console.log("initPush called---------------------------------");
console.log("calling bluemix initialize with values--------------------------------");
IBMBluemix.initialize(values).then(function(status) {
console.log("IBM Bluemix Initialized", status);
return IBMPush.initializeService();
}, function (err) {
console.error("IBM Bluemix initialized failed" , err);
}).then(function(pushObj) {
function pushReceived(info) {
console.log("registerListener - " + info.alert);
alert('got a push message! ' + info.alert);
}
console.log("IBM Push Initialized", pushObj);
push = pushObj;
return push.registerDevice("LisaTest","Lisa123","pushReceived");
}, function (err) {
console.error("IBM Bluemix Push initialized failed" , err);
});
You need to replace "applicationId", "applicationRoute", and "applicationSecret" in the code
var values = {
applicationId:"applicationId",
applicationRoute:"applicationRoute",
applicationSecret:"applicationSecret"
};
with those obtained from your Bluemix backend application.
From the bluemix dashboard for your application click mobile options in the top right to see your ID and Route.
For the secret navigate to the Mobile Application Security dashboard from the link on the right, and your secret will be displayed on that page.

Resources