This question already has answers here:
Badge count is persisted after deleting an app and installing it again
(4 answers)
Closed 5 years ago.
The UIApplication badge number is not deleted at reinstall.
In case I uninstall the application when the badge has a non zero value, and then re-install it, the badge still appears in the new installation.
I update the badge number in the following manner:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:badgeNumber];
Tried to find a solution - some notification when the application terminates so I can remove the badge... Couldn't make it with applicationWillTerminate. Any suggestions?
Apple actually responded and this is the expected behavior, the badge remains for a short period after uninstall (exactly for the case of an immediate re-install).
Try to set:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:-1];
in application: didFinishLaunchingWithOptions:
Worked fine for me.
Related
When application is installed for the first time I am seeing notification badge count as 1 by default. I am not able to find from where it is coming.
I tried many approaches provided over SO, but none of them worked for me.
Add this code in your AppDelegate.m
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
After I install and start my iOS app on device or in the Simulator, the red badge at the corner of the app's icon shows a 5 digits number.
I haven't noticed it for months, then installed some stuff to enable local notifications (linked the standard "PushNotificationsIOS", installed "react-native-push-notifications").
When I saw the bug, I removed everything notifications-related, and yet now I see it no matter how far I go back in my commits history. The number used to change after every notification, but now it is a stable 61'051 after a fresh install.
I would bet that the device is still sending thousands of notifs from an old bug, and the number is the result of a modulo.
What can cause the badge to show up with such a number? What did not get uninstalled properly?
Otherwise, can I remove the badge altogether?
I believe that you scheduled a number of local notifications and would like to get rid of them. Even that you removed all of the notifications related code, it does not mean that already scheduled notification won't be fired. So you have to manually clean them in your code.
If you use iOS 10+ notifications, this may help you:
let center = UNUserNotificationCenter.current()
center.removeAllDeliveredNotifications()
center.removeAllPendingNotificationRequests()
Apple documentation
This question already has answers here:
UIApplication openURL background
(3 answers)
Closed 6 years ago.
I am able to open another application from my application using URL Schemes on a button click or app in foreground.
By using the below code.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"urlscheme://"]];
But, I can not open the application if my application from background.
I have enabled background fetch - It is woking fine.
How can I open the application when background task is running ?
You can not open app in background because In background you can shared resourced , user data.
You can use remote and local notification.
I'm developing an app having local notification scheduled.
I'm not able to cancel the scheduled notification using the code:
UIApplication *app=[UIApplication sharedApplication];
[app cancelLocalNotification:notification];
The code is working well in previous iOS versions, but it is stopped working in iOS 9.2.1 update.
Can anyone please help me to sort out the issue?
There is a bug in iOS 9.2.1, so cancelLocalNotification methods doesn't work sometimes.
Use cancelLocalAllNotifications and update your logic accordingly.
This should work.
Keep your localnotification object in NSUSerDefault when it is scheduling, even if your device gets restart you can retrieve localnotification object from NSUSerDefault. So then after you can easily pass that object in cancelLocalNotification(localNotificationObject) and remove it.
I'm setting my applicationIconBadgeNumber using this code:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:theIntToDisplay];
The problem is that when I delete the app from an iPad and reinstall it, the app icon still shows the previous badge number. Is this default iOS behavior or can we reset it?
I found one similar question on at Why the applicationIconBadgeNumber is not getting deleted with appliccation ? Where it stored actually?, but it didn't answer my question.
This is an expected behavior, the badge number remains for a short period after uninstall e.g for the case of an immediate re-install.
Of course you can nullify badge number after every launching the application in application:didFinishLaunchingWithOptions: method but I think it is not the case because you want badge number not to be shown right after you install app and not yet launch it. In such a case just wait after removing the application and the badge numbers cache will be cleared by iOS and then install the app again. Unfortunately without jailbreaking the device there is no way to manage badge numbers behavior manually
In your app delegate under:
- (void)applicationWillEnterForeground:(UIApplication *)application
{
}
Insert:
application.applicationIconBadgeNumber = 0;