notifications funnel in Firebase Console doesn't marks a message as "Opened" even when the message is delivered and opened - firebase-notifications

i use Firebase with my android app for testing,
then i'm using Firebase console to send a notification to my phone,
the notification is successfully delivered to my phone but when i open it notifications funnel doesn't marks a message as "Opened" .
what things could cause that??
I include an edited image with big red arrow to make thing more clearly,
thank you.
image:http://i.stack.imgur.com/59zTy.png

I do not even see the sent number (it remains 0)

set the following code in the AppDelegate.m and set "FirebaseAppDelegateProxyEnabled = No" in the Info.plist
// With "FirebaseAppDelegateProxyEnabled": NO
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:
(void (^)(UIBackgroundFetchResult))completionHandler {
// Let FCM know about the message for analytics etc.
[[FIRMessaging messaging] appDidReceiveMessage:userInfo];
// handle your message.
}

Related

Push notification data not getting when app launched directly by clicking app icon

I have a scenario in which app will get push notification and need to show that messages in home screen of my app, for that i saved the message array into user defaults from my app delegate and everything works well, but in following conditions it's not working
if app is in killed state and a notification came and user triggeres the app through the app icon (not from push notification )
if app is in background and notification came and user enters to app through app icon (not from push message ) in this case also
Then i searched for solutions and came to know about silent push notifications (for background mode) and nothing else so i need to know how to handle all scenarios by push notifications and my appdelegete is
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSDictionary *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
if (remoteNotif) {
[self handlePushMessage:remoteNotif];
}
return YES;
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[self handlePushMessage:userInfo];
}
-(void)handlePushMessage :(NSDictionary*)userInfo{
//method to handle push message
}
Thanks in advance
This is a common issue: if the user does not open your app by means of the displayed notification, there is no* way of getting the related information.
* A possible solution employed by many apps is to check with a remote server for unread notifications (e.g. check for an unset read-date field).
In scenario 1. NSDictionary *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey]; here remoteNotif return nil as you enter into the app through triggering app icon.
In scenario 2. You can get push notification info through the following method
-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
if (userInfo) {
[self handlePushMessage:userInfo];
}
}
if app is in killed state and a notification came and user triggeres the app through the app icon (not from push notification )
If the app is in killed state then the push notification payload can only be handed over to the app when the user taps the push notification itself. If the user launches the app from app icon then the notification payload will not be passed to the application
if app is in background and notification came and user enters to app through app icon (not from push message ) in this case also
if you are targeting iOS7 and up then you need to enable background mode for remote notifications. Please check below link in order to get notification payload even when app is in background
didReceiveRemoteNotification not working in the background
The above mentioned app delegate method gets called when the app is in foreground,Background and suspended state.
There is no way to get the notification payload when app is killed and when the app icon is directly clicked instead of push notification in notification center.
Enable "Remote Notifications" under background modes in capabilities in target settings. This will fetch the notification data even when the app is in the background. Also, make sure to implement:
-(void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler;
in your app delegate.

Parse not sending push open notifications for iOS7

I have followed the guide for the relevant Push setup with Parse.
When testing the app on an iOS7 device and iOS8 device the same method is called when opening from a push:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
DebugLog(#"%s",__PRETTY_FUNCTION__);
if (application.applicationState == UIApplicationStateInactive) {
[PFAnalytics trackAppOpenedWithRemoteNotificationPayload:userInfo];
}
if (completionHandler) {
completionHandler(UIBackgroundFetchResultNoData);
}
[PFPush handlePush:userInfo];
}
It appears that although the [PFAnalytics trackAppOpenedWithRemoteNotificationPayload:userInfo]; method is called on iOS7 the data is not shown in Parse.
For example, checking the Push that has been sent shows the amount of Opens. If I send a push to an iOS7 device and iOS8, the same part of code is being called. However, it is only recorded for the iOS8 version. Is there anything else I should be doing?
We have followed the relevant guide: https://parse.com/docs/ios/guide#push-notifications
This is also implemented:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
DebugLog(#"%s",__PRETTY_FUNCTION__);
if (application.applicationState == UIApplicationStateInactive) {
// The application was just brought from the background to the foreground,
// so we consider the app as having been "opened by a push notification."
[PFAnalytics trackAppOpenedWithRemoteNotificationPayload:userInfo];
}
[PFPush handlePush:userInfo];
}
The issue was caused by some Notification Permission testing.
When testing notification permissions the prompt will only come up for the first time. To get the prompt to come up again you need to:
Remove the app and reset the device
Turn it on and change the date to a future date, reset again
Turn it on and re-install/build the app, the permission prompt will occur again.
We had been completing this for some testing on iOS7 and iOS8 devices. The issue seemed to be that on the iOS7 device although the push open notification was called it was not recorded, this seemed to be related to the date being in the future.
The date on the iOS8 device was also in the future, but possibly not as far ahead. When the date was set to the correct date on the device the push open notification on the iOS7 device was recorded again.

How can I intercept an iOS Push Notification before it's displayed on the lock screen notification center?

I'm working on integrating an app with GCM in order to get simple global topic Push Notifications. The server side which communicates with GCM is written in Java/Spring, and for the most part is working as expected. However, I'm having issues with something that may not be possible on the iOS side of things.
Ideally, rather than my push notification just being a flat string with a message, I'd like to send over a JSON structure (in string format) with a few bits of metadata, as after the notification is displayed, I intend to keep it around for review elsewhere in the app.
Now, when the app is active, I have no issue, as my app delegate runs
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))handler {
....
}
which with a notification registration in my main viewController, happily passes along the remote notification to my viewController code where I can parse the JSON and do with it how I please.
However, I can't seem to find an analogous method/procedure I can define that gives me the same control to a notification that comes in when the app is not actively in the foreground. This results in a lock screen push notification that's displaying my JSON structure in string format, obviously not what I want.
Now, technically I could simply push the message, and use the message string itself as a unique key to hit my database manually for the metadata, but I'd like to avoid this for two reasons. One, it seems like a waste of time/resources, but two, I'd like some control on the client side of the notifications. I'm having issues where on different devices (iPad 2 vs iPhone 5s), my code will display duplicate push notifications, that is, the iPad gets the push and shows it once, the iPhone appears to receive it twice. I'm worried I'm misunderstanding the usage of
UIUserNotificationType allNotificationTypes =
(UIUserNotificationTypeAlert);
UIUserNotificationSettings *settings =
[UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
[[GCMService sharedInstance] startWithConfig:[GCMConfig defaultConfig]];
these lines and how they effect what gets displayed on the lock screen, but regardless I'd still rather have manual control if it all possible to ensure duplicates are never displayed.
You can send whatever you want trough notifications, there some value that you iOS device will take as mandatory, if you send the following message you can show some message and send additional data with the notification, imagine this base notification:
{
aps: {
alert: "Hi there"
}
}
This notification will show the alert message on the lock screen and the notification bar on you device, but can also send this:
{
aps: {
alert: "Hi there",
content-available: 1, // Add this if you want background processing
sound: "" // If you don't want to show the notification on the notification area nor the lock screen.
}
data: {
effectiveTime: ...,
expirationTime: ...,
message: ...,
...
}
}
This will show exactly the same notification on you device than the first one, but in this case you can do anything you want with the data using didReceiveRemoteNotification: method
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(#"My data sent trough GCM: %#", userInfo[#"data"]);
}
The only keys you can use to your data are the listed in 3-1 and 3-2 on the official push notifications docs
If you want to manage background processing, according to the docs you should use (as you said) the application:didReceiveRemoteNotification:fetchCompletionHandler: but everything else remain the same:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler {
switch (application.applicationState) {
case UIApplicationStateInactive:
// Do whatever you want if the app is inactive
handler(UIBackgroundFetchResultNewData);
break;
case UIApplicationStateBackground:
// Do whatever you want if the app is in background
handler(UIBackgroundFetchResultNewData);
break;
case default:
// Do whatever you want if the app is active
handler(UIBackgroundFetchResultNewData);
break;
}
}

Get push notification data when application is in background IOS

Hi I am developing small IOS application in which I am using push notification. So in my case I am able get notifications and I am also able to access data for notification. Data from notification mean title, description etc. So in my case I am not saving my notification at my server side. I want to save those locally. For that what I want as soon as notification come I want to save that data locally. I am able to access my data when App is in foreground but I am not able to access my notification data when app is in background. I want to access the data of notification so that I can save it. For notification I did following things:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[application registerForRemoteNotificationTypes:
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
return YES;
}
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken {
}
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
for (NSString *key in [userInfo allKeys])
{
NSString *data = [userInfo objectForKey:key];
NSLog(#"inside did register for notification .... %# ---- > %#",key,data);
}
}
My requirement is simple I want access to notification when my app is in background. Any one is here who already did this? Need Help. Thank you.
In iOS, the app cannot access it's push notification until the user taps on the push notification from the notification center.
Once the push notification is tapped and the app loads/becomes active, only then will you be able to access the push notification.
FYI:
When the app is in background and a push notification is recieved.
After the user taps on the push notification:
the contents will be accessible in the -didReceiveRemoteNotification: method.
When the app is not open and a push notification is received.
After the user taps on the push notification
the contents will be accessible in the -didFinishLaunchingWithOptions: method in it's launchOptions parameter.
Also... push notifications aren't 100% reliable. They may or may not be delivered (although them not being delivered is pretty rare in my observation but worth pointing out none-the-less)
There is a way in iOS 7.0 and later where you can send notifications and access its content without user tapping it.
So, the notification payload which you send has a parameter called content-available. You can view the payload parmeters in the following link:
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html
So when you set the content available to 1 and deliver the notification, iOS calls the below function even if the app is not in the background or foreground(must have remote notification enabled)
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
Then you can use the userInfo dictionary to fetch your notification data.

Is this possible to handle which iOS notification is clicked on the notification centre?

I would like to know, if the user click the notification in the notification centre, whether the application can detect which notification they are clicking and how I can handle it? Thanks.
Yes. In your app delegate, the notification details will be received in the method - (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
The userInfo will have the payload that you sent with your push notification. It recommended that when you send a push notification that you include identifying information in the payload (such as an object id) to figure out which push notification was selected/received.

Resources