So it's a pretty straight forward problem. My server sends an APN to the iOS device, I can click on the notification and the app launches and everything works as it should, but the notification never gets dismissed, it just sits there in notification centre.
Any help would be greatly appreciated!
Apologies if this has been answered before, I've searched all over stack and only found reference to local notifications.
Edit
Ok, so when I put
[UIApplication sharedApplication].applicationIconBadgeNumber=0;
[[UIApplication sharedApplication] cancelAllLocalNotifications];
in the application:didFinishLaunchingWithOptions it dismisses any old notifications when the app is launched (and no this doesn't happen by default when the app launched anyway), but when I put it in any of the other delegate methods that get called when the app becomes active like applicationDidBecomeActive: it doesn't work?
This is making very little sense...
Adding in:
application.applicationIconBadgeNumber = 0;
into applicationDidBecomeActive: did the trick!
Related
I can't find any right solution even after long searching. What is normal scenario in iOS in belows?
When the app gets local notification,
1) didReceiveLocalNotification is invoked when the app is in foreground. and also is invoked when notification banned touched launch.
However, under the same situation,
2) didReceiveLocalNotification method is not invoked by app icon touched launch.
Stackoverflow or Apple document said
in case of 2), applicationWillEnterForeground -> didReceiveLocalNotification -> applicationDidBecomeActive delegates process is normal. but I've never seen didReceiveLocalNotification in the case of touching app icon.
Please, give me an advice case 2) is normal or not. Help me!
Edit -
After having couple of comments, I've found a link such as Handling local notifications when the user presses the icon instead of the alert
This approach would be working I believe. Thanks.
Edit2 -
Local Notification
This link would be helpful as well.
That method is only called when your app is launched as a result of interacting with a local notification. Not seeing it called during a normal app launch is expected behaviour.
I have been doing some research, but can't seem to get this to work. Is there a way to present a UIAlertView in your app after a person received a push notification while the app was in the background, or inactive? I have tried putting code into the didReceiveRemoteNotification, but it only works when the application is active. Can someone point me in the right direction?
According to the documentation -[UIApplicationDelegate application:didReceiveRemoteNotification] get's only called when the app is in the foreground. Starting with iOS7 you should actually use -[UIApplicationDelegate application:didReceiveRemoteNotification:fetchCompletionHandler:] which will be called both when in foreground and in background.
So and so you are by design prohibited to invoke any UI change when the app is in the background (e.g. showing a UIAlertView will be ignored). You could however set yourself a flag -[UIApplicationDelegate application:didReceiveRemoteNotification:fetchCompletionHandler:] and then when check for it and present the UIAlertView in -[UIApplicationDelegate applicationWillEnterForeground:].
I use a phone gap plugin and xcode 5.
Lets see the example of the problem:
The application is in background or closed.
I send the notification.
User sees the notification pop up, without clicking on it.
I send another notification.
If user open notification bar it will see two notification actually i want
to delete the previous some how and present to user only the second notification.
The eqvivalent in java is NotificationManage.cancelAll();
For now each/all notification i send are shown when user open notifications bar.
Any help appreciated.
You have (the app has) no control over that.
The user controls how many notifications they see in notification center. Notifications can be removed by the user and will be removed when acted upon (the app is opened from the notification).
You can do this by [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
in the method didReceiveRemoteNotification. In this way notification center will be cleared.
Here's my app scenario: When user swipes a notification I will launch some other app via URL.
So it basically launches some other app when notification arrives.
Currently to handle swiping notification scenario, when
- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)
method is invoked, within this method, I call processNotification: method, which contains:
...
[[UIApplication sharedApplication] openURL:url];
...
If push received while app is active, url is opened perfectly fine.
If push received by swiping or clicking on notification, url is opened in the background but the currently viewed app is my application. For example if my url is tel:123-456-7890, iOS starts the call (you can hear the sound) but active app is not Phone.app, it is my app.
That seemed pretty strange to me. However if I wait for UI to load, and call processNotification: after that, it brings up Phone.app window correctly. (bug in platform? because call happens but my UI is on the top.)
I need a method to delay execution of this processNotification: call, (maybe through an operation queue) until a view controller is loaded. Otherwise, my app stays on top and the URL is opened in the background.
I was facing the same issue, I moved the openURL into main_queue and it seems to be working fine. I did not have to even make that change in didBecomeActive
dispatch_async(dispatch_get_main_queue(), ^(void){
[[UIApplication sharedApplication] openURL:url];
});
You should delay your handling of the push notification (i.e. calling openURL:) until applicationDidBecomeActive:. Keep the parameters you need from application:didFinishLaunchingWithOptions: but only call your handling code in applicationDidBecomeActive:.
I think the problem here is that SpringBoard is unable to cope with one app transition being called while another is in progress. An iOS bug of course. You should open a bug report at https://bugreport.apple.com
When I run the app on my iOS 7 device, the app doesn't appear on the device notifications settings and doesn't sounds when a notification is being fires. Only after the first notification is being fired, I can see my app under the list of the notification settings with sounds turned off.
Why doesn't the app show in the notifications list initially?
Why are the sounds turned off by default?
On iOS 5&6 I don't have these problems. These are local notifications.
It looks like iOS 7.0.3 includes a fix for that.
Have you set the applicationIconBadgeNumber in "- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions"? Comment this code, and try again.....I don't why, but I got the same problem. After I commented this line, my app works correctly.
I got this same problem. What i found out was, i have a piece of code that caused this all along.
In my AppDelegate didFinishLaunchingWithOptions, i have implemented:
//remove this if you have it
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0]; //to reset the badge everytime the app loads
So what i did, I removed that code & redeploy the app. Now it has ON default value in Notification Center.
Phew.
Hmm,
Interestingly, I changed the order of
notification.SoundName = UILocalNotification.DefaultSoundName;
notification.ApplicationIconBadgeNumber = 1;
to
notification.ApplicationIconBadgeNumber = 1;
notification.SoundName = UILocalNotification.DefaultSoundName;
and it works now. When the app is running in background, the local notification fires and plays the default notification sound.