I'm developing an app in Windows Phone 8.1 (NOT silverlight) which uses WNS to receive raw push notification.
While I run my app through Visual Studio (over a physical device, not in the emulator), I always receive push notifications (with the app in foreground, in background, with the phone locked...) so I think my code to receive push is correct.
My issue is when I run my app whithout using Visual Studio. If I press the "app icon" on the device to init the app and keep it in foreground, I receive push notifications. But if I go to the phone menu, or lock the device (without killing the app), I don't receive push notifications, but the server says that WNS has been sent successfully. If I put the app again into foreground, I receive push notifications again...
So, summarizing: Init app through Visual Studio, I receive always the WNS notifications. Init app through device, only receive WNS with the app in foreground. The server always send the WNS successfully.
Here is my code to receive WNS:
public static void OnPushNotificationReceived(PushNotificationChannel channel, PushNotificationReceivedEventArgs e)
{
Debug.WriteLine("Received WNS notification");
string notificationContent = String.Empty;
switch (e.NotificationType)
{
case PushNotificationType.Badge:
Debug.WriteLine("Badge notifications not allowed");
return;
case PushNotificationType.Tile:
Debug.WriteLine("Tile notifications not allowed");
return;
case PushNotificationType.Toast:
Debug.WriteLine("Toast notifications not allowed");
return;
case PushNotificationType.Raw:
notificationContent = e.RawNotification.Content;
break;
}
processWnsNotification(notificationContent);
}
//Show local toast notification
private static void processWnsNotification(string notification)
{
ToastTemplateType toastTemplateXml = ToastTemplateType.ToastText01;
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplateXml);
XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
toastTextElements[0].AppendChild(toastXml.CreateTextNode("New message"));
ToastNotification toast = new ToastNotification(toastXml);
if(toastNotifier == null)
{
toastNotifier = ToastNotificationManager.CreateToastNotifier();
}
toastNotifier.Show(toast);
}
Anyone know what happens or what I'm doing wrong?
I think it could be a configuration issue... but I've been digging into property and config files without success.
Thanks a lot!!
Jorge.
This is the expected behavior and is very well documented, that your app will receive raw push notifications only when it is not suspended or when a background task is registered which can handle raw notifications.
You receive them when Visual Studio is open because when the debugger is attached the app does not suspend. To debug the suspension of an app, go to View->Toolbars and enable the Debug Location toolbar, then start your app, and select the Suspend option from the Lifecycle Events box. You will notice that your code does not execute (test with breakpoint).
The notification may be sent by your server, but will not be received by your phone. You probably don't check the responses of your push requests, but there should be some indication that the client is not available or something similar (a status code that states that maybe).
Related
I'm having an issue with FCM on flutter. I have implemented messaging from my server so I'm storing my phone token for each user.
The thing is that when a user logs in for the very first time everything works properly, messages are being sent and user gets notified.
If I do not use the app during the weekend, on Monday I try to send a message by doing some actions on my app but messages are not being sent. I can see my token stored properly in my database.
I'm using firebase_messaging 2.1.0 for flutter.
This is how I get my token
_fireBaseMessaging.getToken().then((token){
_myPhoneToken = token;
});
1-I know token may change when:
App deletes Instance ID
App is restored on a new device
User uninstalls/reinstall the app
User clears app data
But none of this happens.
Any advice on how to handle this scenario? thanks in advance.
UPDATE
Provided you have setup the FCM sdk the right way (but you said that it works the fist time you install the app, so I guess so).
Provided that you are sure that the device_token you are using is the one of the device on which you are expecting to receive the notification (check if it's still the same), you should get on this device your notification quite soon if you use "priority" : "high".
{
"to" : "device_token",
"priority" : "high",
"notification" : {
"sound": "default",
"body" : "Test Notification body",
"title": "Test Notification title"
}
}
This method call
_firebaseMessaging.getToken().then((String token)
return always the new token even if it has been updated. So if you print this out on your device and you send a notification on this token without error, there's no reason why you should not get the token if the device has a valid internet connection active.
It's true that the device token can change during time. If you uninstall and reinstall the app, you can see the token will change and if you try to send a notification on the old one, you will get an error.
If instead the token will change during application lifetime, you can be notify on your server side by listening:
_firebaseMessaging.onTokenRefresh.listen((newToken) {
_fcm_token = newToken;
// send the new fcm to your server
});
So first of all I suggest you to be able to send a notification to a device with Postman. Check if the token you are using is still the one on the device. Then you can try to uninstall and reinstall the application and try to use the old token. You will get an error. Then try to send to the new one, and you should get your notification.
Then wait for some days and try again, check if the token has changed or not and if it's not changed you should be able to send the notification without problems with the same token.
Also be aware that data message on Android if the app is terminated are still not supported.
Some networks/router/mobile can cut the connection between firebase library and firebase server due to inactivity (5min without message). This cut may be detected by the library up to 30min (FCM heatbeat interval).
These are some links discussing this issue:
https://github.com/firebase/quickstart-android/issues/307
Android: Delay in Receiving message in FCM(onMessageReceived)
I contacted firebase support but they told that since the issue is caused by external part they cannot fix it (I suggest decreasing heartbeat interval ...)
I fixed it in android using an interval job which apply these instructions:
context.sendBroadcast(new Intent("com.google.android.intent.action.GTALK_HEARTBEAT"));
context.sendBroadcast(new Intent("com.google.android.intent.action.MCS_HEARTBEAT"));
You may write this specific code for Android side and should find something similar for ios side.
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 am implementing push notification in Android ported BB 10 app. I am using Push Sharp in sevrer side to send notification. Below is my code:
bbBroker.QueueNotification(new BlackberryNotification
{
Recipients = new List<BlackberryRecipient> { bbReceipent },
Content = new BlackberryMessageContent(json),
SourceReference = "myappid"
});
bbBroker.OnNotificationSucceeded += (notification) =>
{
Log.WriteLog("BBB Notification Sent Successfully");
};
OnNotificationSucceeded is called, but in my device I don't see any notification.
One time I heard only sound and red color icon on my app. I was not aware how to view notification, I uninstalled the app, then again installed it. Then I pushed some text, but now even sound also stopped coming.
Please someone guide me what is going on?
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.
I want to send the email from my QTSimulator. I am using the following code for send the email.
QMessage msg;
msg.setType(QMessage::Email);
// Set recipient for our email message
QString recipient("xxxxx#gmail.com");
msg.setTo(QMessageAddress(QMessageAddress::Email, recipient));
// Define message subject, body and append attachment
msg.setSubject("Messaging API example");
msg.setBody("Hello,\n\nthis is an example message.");
// Send message using a new service handle
QMessageService* svc = new QMessageService();
if (svc->send(msg))
qDebug("Successfully sent message.");
else
qWarning("Failed to send message.");
But I got the following error...
"Invalid message account ID
Failed to send message."
Please help me.. Thanks is advance.
Is it possible to send mail from QT-Simulator? Can we do any configuration for network connectivity?
As far as I know this isn't possible. Qt simulator only has feature to simulate incoming messages so you can test how your app handles them.
Once I had qt mobility with messaging compiled on my own (under windows), so it was intergrated with ms outlook. Once email was received by Outlook, messaging sent notification. I guess this would work in an opposite direction. This worked in Qt Simulator as well (but button responsible for simulating new message was not working).