Not receiving push notifications in background, only foreground (no alerts) - ios

I've set up my app for push notifications, and for the past few days of development I've received zero notifications when the app is in the background. No alert, badges, sounds -- nada. Nothing shows up in the notifications area when you swipe down the screen from above.
But when the app is in the foreground, application:didReceiveRemoteNotification: does indeed fire off. When I first started messing around with notifications, I was getting them, but at some point it just stopped working. I've verified that the phone has notifications enabled for the app.
I'm using Quickblox to send cross-platform push notifications, and they have a control panel on their website where you can send notifications. When I sent one through there, I receive it in the background. On the foreground, this is what I see as the log output for the ones sent from the control panel:
2015-07-11 00:11:26.755 Viewerapp[6671:2177549] didReceiveRemoteNotification userInfo={
aps = {
alert = "Testing push notification";
sound = default;
};
}
And this is what I receive when the client app uses the Quickblox API to send a push notification:
2015-07-11 00:14:14.907 Viewerapp[6671:2177549] didReceiveRemoteNotification userInfo={
QBUserID = 2574021;
aps = {
alert = "";
};
messageOS = Android;
messageText = "Push notification test";
messageType = "simpleMessage";
userName = John;
}
Is the problem that the latter lacks data in aps? Does it seem like it's a Quickblox issue?

Related

How handle silent push notification when application is InActive state in ios 9?

I have implement silent push notification.So "didReceiveRemoteNotification" method called when application is inactive state in ios 9.
There are some case when application is inactive state.
1.When user tab on particular notification.
2.When call or message receive.
3.When notification center and control center open.
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
if(application.applicationState == UIApplicationStateInactive) //Inactive state
{
[self RedirectScreenBasedOnNotification:self.userInfoDic];//Screen Redirection code
}
}
So how can i handle silent notification when app is inactive state?
I have face problem is when notification center open at that time if any notification come then redirection will do,but i want to stop that.
Notification payload:-
aps = {
alert = "Test Dev 5 startd following you ";
"content-available" = 1;
"link_url" = "https://raywenderlich.com";
message = {
friend = {
email = "abc#gmail.com";
name = "Test Dev 5";
photo = "";
"user_id" = 27;
};
id = 3;
"is_business_sent" = 0;
message = "Test Dev 5 startd following you ";
};
sound = default;
}
Thanks in advance
Silent push notifications do not trigger user interactions. When a silent notification payload includes keys for user interaction things go wrong - iOS can't reason about wether the intent is to present something to the user, or to keep the notification silent and handled without user interaction. Sometimes the silent notification may work, other times it may be presented like a normal notification with user interaction. It can be one or the other, not both.
If the silent push key content-available is present in the aps payload the keys alert, sound, or badge should not be.
You can use my Push Notification Payload Validation Tool to check the content of your notification. The payload you posted in your question has several problems - the aps key should only contain Apple keys defined in Generating Push Notifications. All of your custom keys and values should be outside the aps object.
application:didReceiveRemoteNotification:fetchCompletionHandler: will only be called for silent push notifications. If the notification payload contains both content-available and one or more of alert, sound, or badge iOS will not know which method to call and you may see inconsistent behavior.
If you are just trying to show a non-silent notification you do not need to implement application:didReceiveRemoteNotification:fetchCompletionHandler:. Instead implement application:didReceiveRemoteNotification: for iOS 9 and userNotificationCenter:willPresentNotification:withCompletionHandler: for iOS 10 and later.
As far as silent notifications and the inactive application state, there is nothing special to be done here. Silent notifications are intended to 'hint' to the application that it should refresh content. When a silent notification is received the application is required to process the content update within 30 seconds and then call the fetch completion handler. When iOS executes the fetch completion handler it take a new restoration snapshot of the updated UI. This happens even when the application is inactive.
You can add your code in this If condition.
if (UIApplication.sharedApplication.applicationState != UIApplicationStateInactive) {
//Write your code her, this will get executed when your app is not in Inactive state.
}

iOS doesn't receive Push notification when the app is being killed

I have found similar questions on Stack Overflow, but none of them have cleared the point.
I am using Firebase Cloud Messaging for sending push notifications in my app. I am storing the messages received in a local database. When my app is active or in the background, my app is able to receive the notifications (delegate methods called properly) but if the app is being forced quit or not in the memory then also the device is receiving the notifications and sat in notification center but the none of the delegate methods called when the app is being launched by an icon. If a user clicks on Message in the notification center, then the app gets launched, but only the message clicked on is being received and not all of them (in the case of multiple notices have been received).
According to Apple - The system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.
But even if the user launched the app still not receive the notifications which were received and sat in the notification center.
Here are the points followed by the app:
My app has no VoIP functionality.
Content-available has been set to 1.
Has enabled to receive background remote notifications.
All notifications sent has been received and displayed in the notification center.
{
aps = {
alert = {
body = "Push Notification Test Message";
title = Push Notification;
};
badge = 1;
"content-available" = 1;
sound = default;
};
"gcm.message_id" = "0:1499340350307980%361a2e5b361a2e5b";
m = "Push Notification Test Message";
tag = m;
}
If the app is being forced quit or not in memory then your app will not receive silent notifications(i.e. Content-available set to 1).
Only push notifications are received in above conditions.
If user clicks on Message in notification center, then app gets launched and only that clicked the message will be received in delegate methods.You cannot access all the messages in the notification tray.
There is no way to get push notifications for the application if app is not running. This is restriction . You are only can get and clear local notifications. So the another way of resolving your problem is saving your notification on the backend when you send it. Then after launching app , you can get notifications list from the server , and match it with id . You can send any parameters that you want in notification playload.
Your app should not rely on the delivery of push notifications. Delivery of push notifications is not guaranteed, as you have found.
Even if your app isn't terminated you may not receive all notifications; For example if the device is in airplane mode and multiple notifications are sent, only the last one is delivered when the device comes back online.
Your app should check with the server for new messages when it is launched or when a notification is received in order to "catch up".
You can also consider including a message payload in your silent notifications. This will be displayed to the user if your app is terminated to prompt them to open your app.
You need to handle method for push notification when the application is open from a tap on any notification. As soon as you tap on notification application will awake and lunch it.
In didFinishLaunchingWithOptions, you need to put below condition:
if (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]) {
NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithDictionary:[launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]];
}
It also called below method when notification is tapped:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
{
}

iOS - Detect Push Notifications when the App is terminated by the user

I have a problem. When my App is Terminated by the user, push notifications are not detected by the application. The push notification is sent with content_available = true.
What should I do?
This is default system behaviour. If you Application is terminated by the user (from the App switcher), Silent Push Notifications (content_available = true) will not wake the Application, i.e. Application:didreceiveremotenotification will not be called.
If you want the user to be notified, do not send a Silent Push Notification. Send a normal push notification which will show up in the user's notification tray.
That is the way how it works on iOS.
If you app is not running at all, your app receive no push notifications at all. Only if the user swipe over one of your push notifications on the lock screen or the notification center your app will be started and you will be notified that your app was started because of the push message.
If you app is in the background, you actually can handle push notifications by enabling "run in background" support.
I'm talking iOS9 and earlier here. Not sure if the behaviour has been changed in iOS10. But if you are coming from Android then you have to accept that push notification handling works completely different on iOS than on Android.
Sending the notification with the content_available as disabled. content_available = 0
The content_available field is used for sending silent push notifications to process in the background and will not display as a notification.
See documentation : https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/TheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH107-SW6
Hope this helps,
DT
Make sure that in your push notification payload you are adding priority:"high". It will ensure that your app will receive a Push Notification in background or closed mode.
{
"to" : "/topics/{userId}"
"content_available":true,
"priority":"high"
"notification" : {
"title": "",
"body":""
},
"data" : {
//custom key value pairs
}
}

Xamarin.Forms iOS Can't Customize Notifications

I've been following the tutorial found at: https://azure.microsoft.com/en-us/documentation/articles/partner-xamarin-mobile-services-xamarin-forms-get-started-push/ to try and get push notifications to work in my Xamarin.Forms app.
I've got them working on Android, but I'm having a bug on iOS - I need to customize the text (from the phone) before the notification is actually made, but I can't on ios since when the app is running in the background, ReceivedRemoteNotification isn't being called.
Here's something similar to what my notification handling code looks like:
public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
{
NSObject inAppMessage;
bool success = userInfo.TryGetValue(new NSString("inAppMessage"), out inAppMessage);
if (success)
{
//change the text that is displayed
string newNotText = ModifyNotification(inAppMessage.ToString());
var alert = new UIAlertView("Got push notification", newNotText, null, "OK", null);
alert.Show();
}
}
How can I customize a notification that is received on iOS?
iOS Push and GCM is different in how they work, GCM lets the App handle the notification and start the local notification, iOS does not.
iOS only notifies your App that the notification existed, but there are a workarounds for this.
On iOS you can use silent notifications which are not seen by the user but you'll get the ReceivedRemoteNotification callback
You can read more here: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html
This documentation tells you the following:
The content-available property with a value of 1 lets the remote notification act as a “silent” notification. When a silent notification arrives, iOS wakes up your app in the background so that you can get new data from your server or do background information processing. Users aren’t told about the new or changed information that results from a silent notification, but they can find out about it the next time they open your app.
So if your notification contains the "content-available" with value 1 it will be silent and you can start your own local notification after this.
Be prepared that this is not reliable in any way and if you are not a special privileged app(like VOIP) you are not able to do what you want in a reliable way on iOS
Backend example:
Just change the template var like in your tutorial used:
const string template = "{\"aps\":{\"content-available\":\"1\",\"alert\":\"$(message)\"}}";
Because it is not clear enough, if you don't want to get any notification you should not use alert or sound properties for your notification
const string template = "{\"aps\":{\"content-available\":\"1\",\"someproperty\":\"propertyvalue\"}}";

Track remote push notifications when app in background

I use Urban Airship to handle remote push notifications for my iOS app. It works as expected, and I get notifications both in foreground and in background. I would however like to track all incoming remote push notifications (even if they are not executed). So if a remote push arrives, I would like to invoke some code to record what kind of notification it was. I seem to only be able to handle when a user taps a notification, and not when it is received. Is this possible?
I have set Background mode to "Remote notifications", implemented both didReceiveRemoteNotification in appdelegate and a both receivedBackgroundNotification for urban airship. I have also set backgroundPushNotificationsEnabled to yes.
Any ideas if this is even possible?
Here is an example of a push notification:
{
"_" = "Q-Pr3MeyLaEeS8csDiudL0-A";
aps = {
alert = "A simple message";
badge = 53;
};
id = ea591946c21d437f8fc1c851e1c1e728;
pid = 6a26766232e14d971dc1417a0c217bfc;
type = c1;
}

Resources