I'm a Xamarin dev, but I'm exploring Nativescript.
So I've a question.
Which is the better Push notification system to use with Nativescript?
I like to use Visual Studio App Center. Is't nativescript compatible?
Thx.
Nativescript community advises to use https://github.com/EddyVerbruggen/nativescript-plugin-firebase for push notifications. You can use Visual Studio App Center for nativescript cloud builds.
Of course Firebase will be my recommendation too as it's one single plugin for most common requirements that includes Push Notification.
But if you have plans for using other third parties, there are plugins available for Urban Airship, Azure etc., It's also possible to manage your own backend for sending Push Notification.
I would recommend using nativescript worker
https://docs.nativescript.org/core-concepts/multithreading-model
and nativescript-local-notifications plugin
in your ./worker/sendpush.js
require('globals');
var notification = require("nativescript-local-notifications");
onmessage = function(msg){
if(msg.data.success == true)
{
notification.schedule([{
id : 1,
title: 'New message',
badge : 1,
body: data.msg,
smallIcon : 'res://icon'
]).then(function() {
console.log("Notification scheduled");
},function(error) {
console.log("scheduling error: " + error);
})
}
in your main-page.js
var getloc = new Worker("./workers/get-location");
getloc.postMessage({msg : "blabla", success : true});
Related
Hello I'm using Flutter to build my app and I need to to show an alert whenever a new notification is received.
I've been using firebase_messaging 7.0.3 but I run into an error with onBackgroundMessage. A quick Google search helped me find out that the error I was getting hasn't been fixed yet. However one of the devs posted an update 20 days ago about a new version of the package which fixed that issue.
The new version removed the old onMessage handlers and introduced new ones.
Now they got new event handlers which return streams, but haven't been able to make them fire by using the
.listen() function. Whenever I receive a notification a get a this: D/FLTFireMsgReceiver(22032): broadcast received for message printed in the console but the code in the .listen() doesn't get executed.
Here is a link to an article on Firebase Flutter that is a guide for using the new version of the package.
Here is my code:
...
FirebaseMessaging.onMessage.listen((event) {
// do something
});
FirebaseMessaging.onMessageOpenedApp.listen((event) {
// do something
});
FirebaseMessaging.onBackgroundMessage((message) {
// do something
return;
}
...
A solution I found to get the events to fire was to always call:
await FirebaseMessaging.instance.getToken();
right after the
await Firebase.initializeApp();
Once I call that, the FirebaseMessaging.onMessage.listen catches the event as expected.
I was getting the same log when my app is in doze mode for the Data notification with high priority.
This is because of some issue in the firebase-messaging plugin.
Firebase_messaging plugin internally uses JobIntentService to process background fcm notifications
JobIntentService has one constraint in Android O or later versions, when running a Job it will be subject to standard JobScheduler policies. The job will not run immediately while the device is in doze mode. (reference link)
The same issue was raised in the firebase_messaging git repository(bug link)
Solution
One Signal(another push notification provider) solved this issue by having a modified version of JobIntentService. (OneSignal Solution)
At a high level, it uses wake locks for high priority fcm notifications to run service even in Android O and above.
Add this Pull Request changes in your ide by editing respective files.
TL;DR
Add this Pull Request changes in your ide by editing respective files.
Send Data notification with High priority.
FCM Payload:
{
"message": {
"token": "fcm_client_token",
"data": {
"title": "Hello",
"body": "Test Message"
},
"android": {
"priority": "high"
}
}
}
I have a Flutter application using the firebase-messaging plugin for push notifications.
I register firebase like normal on the client, and I send the fcmToken to the server.
Notifications are created via a python server using aiofcm (which uses firebase's XMPP api). They're created like this:
message = aiofcm.Message(
device_token = t2,
notification = {
"title":notification_title,
"body":notification_body,
"sound":"default",
"tag":link
},
data = {
"click_action": "FLUTTER_NOTIFICATION_CLICK"
},
priority=aiofcm.PRIORITY_HIGH
)
await fcm.send_message(message)
On iOS, notifications pop-up at the top of the screen.
On Android, only the icon shows up in the notification tray - not any of the notification content. This is tested on a Pixel 3 and a OnePlus 6, both running Android P.
Ideally, I would like the notification to be "heads-up" style like this:
Before I was able to accomplish this using data messages and creating the notification programmatically in native android, however I would like to avoid that if possible since data messages don't get delivered on Android if the app is terminated.
To Get heads-up - Notification - Kindly set "alert: true"
Example :
notification = {
"title":notification_title,
"body":notification_body,
"sound":"default",
"alert" : true
"tag":link
},
For heads up notification you will need to use flutter_local_notifications Plugin. It is even recommended in FlutterFire official documentation for notification to show notification in foreground (background notification also supported ofcourse!) and it shows heads up notification by default.
You should check out the firebase.flutter.dev docs it shows how to do this easily with the help of flutter_local_notifiation
you can use background fetch and local notification package for background app running.
I'm using react-native-firebase with firebase-messaging to implement push notifications.
While I can send push notifications to everyone, I'm unable to send them to individuals. To my knowledge, all I need is the FCM Registration Token which I retrieve by following the documentation
firebase.messaging().getToken()
.then(fcmToken => {
if (fcmToken) {
console.log("fcm token", fcmToken);
} else {
console.log("fcm token", "null");
}
});
The token I receive is a plausible token, but when I copy that token from the logs into the firebase console and try to send it to a single device, nothing is received. (If I push to a user segment, it's received by all devices with the app installed).
As I can not test for iOS, this might or might not also be a problem on iOS.
In my build.gradle file, the firebase relevant libraries are included like so:
compile(project(':react-native-firebase')) {
transitive = false
}
implementation "com.google.android.gms:play-services-base:15.0.1"
implementation "com.google.firebase:firebase-core:16.0.1"
implementation 'com.google.firebase:firebase-auth:16.0.2'
implementation "com.google.firebase:firebase-messaging:17.1.0"
In the MainApplication.java file I add them to the list of ReactPackages.
new RNGoogleSigninPackage(),
new RNFirebasePackage(),
new RNFirebaseMessagingPackage(),
new RNFirebaseAuthPackage()
My AndroidManifest does not have any Firebase relevant changes as I discovered that push notifications were working even without them. (While trying to implement push notifications I noticed that all phones were receiving them except the one I was actively working on - so I rolled back the code.)
edit: I managed to receive one single device notification. Without any changes, it was suddenly working exactly once. Now it doesn't work anymore.
I'm using FCM to send message from device to device by apply code below, its work perfect on all android devices and iPhone SE, other iPhone device (such as iPhone 6S, 7, 8, X) so on has no pop up the notification or alert, is that any payload code that suit for both platforms?.
I had searched a lot difference solutions but still not working, could anyone help me, Thank you.
}).then(result => {
const token_id = result.val();
//const userNameGet = result[1].val();
const payload = {
notification: {
title : "Message",
body: `${userNameGlobal} has sent you a message`,
sound: "default",
priority: "high",
icon: "default"
}
};
return admin.messaging().sendToDevice(token_id, payload);
}).then(response => {
console.log('This was the notification feature.');
return true;
});
its work perfect on all android devices and iPhone SE, other iPhone device (such as iPhone 6S, 7, 8, X) so on has no pop up the notification or alert
This is very confusing. But basing from the post title, you want to know more about sending messages to different platforms.
I had searched a lot difference solutions but still not working
It would be best for you to include the link/solutions you already checked and results in order for the community better help you next time.
With all that said, at first I intended to suggest FCM v1's Platform Overrides, but noticed that you are using (correct me if I'm wrong) Firebase Admin (or possibly Cloud Functions).
When using the Firebase Admin SDK to send message, there are actually parameters you could use in the payload to specify items unique to each available platforms (Android, iOS, and Web) which is specified in the docs:
Top-level message parameters
android - An object comprised of fields specific to Android messages. See Android-specific fields for details.
apns - An object comprised of fields specific to Apple Push Notification Service (APNS). See APNS-specific fields for details.
webpush - An object comprised of fields specific to WebPush protocol. See WebPush-specific fields for details.
We're using Pushwoosh services to send push notifications to our applications and we've followed the tutorial for Windows 8 (javascript). We were able to have the push notifications working in our application when running on the desktop computer. This is a Windows 8.1 Universal App, so we run the same code for our Windows Phone 8.1 version, which is also in javascript.
In the Windows Phone device the push message is not being received and it often blocks in the "service.subscribeToPushService();" method. Uninstalling the app and running it for the first time seems to work, but after that it just keeps blocking in that method.
Being an universal app, is there any difference between the phone and desk top version in terms of push notifications that we should be aware of?
Are you sure you are using the latest Pushwoosh Windows 8 SDK? If you are using Universal app for Windows/Windows Phone 8.1 you will need to use Pushwoosh Windows 8 (WNS) Pushwoosh SDK for both platforms. It is located here:
https://github.com/Pushwoosh/pushwoosh-windows-8-sdk
The code should be exactly the same for all platforms:
https://github.com/Pushwoosh/pushwoosh-sdk-samples/blob/master/Native/Win8/Win8JS/js/default.js
var service = new PushSDK.NotificationService.getCurrent("YOUR_PUSHWOOSH_APP_ID");
service.ononpushaccepted = function (args) {
//code to handle push notification
//display push notification payload for test only
var md = new Windows.UI.Popups.MessageDialog(args.toString());
md.showAsync()
}
service.ononpushtokenreceived = function (pushToken) {
//code to handle push token
}
service.ononpushtokenfailed = function (error) {
//code to handle push subscription failure
}
service.subscribeToPushService();
Also don't forget to handle launch push notification:
app.onactivated = function (args) {
if (args.detail.kind === activation.ActivationKind.launch) {
showProgress();
if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated)
{
// TODO: This application has been newly launched. Initialize
// your application here.
//Handle start push
PushSDK.NotificationService.handleStartPush(args.detail.arguments);
Also the same information here:
https://community.pushwoosh.com/questions/1801/push-notification-to-windows-81-universal-apps?page=1&focusedAnswerId=1871#1871
You can read this topic here about push notification, there's a section talking about DOS Attacks protection. May something to be with the connection reopening frequency.
Tip: Refrain from opening and closing the connections to the APNs for each push notification that you want to send. Rapid opening and closing of connections to the APNs will be deemed as a Denial-of-Service (DOS) attack and may prevent your provider from sending push notifications to your applications.