This question already has answers here:
iOS badge number live update
(3 answers)
Closed 8 years ago.
I have an app that I want to update the badge icon weekly. I see that at least pre iOS7, UILocalNotification could only set the badge icon to a specific number like
someLocalNotification.applicationIconBadgeNumber = 42;
But I want my app to load in the background lets say every sunday, do a calculation based to get the difference between the current date and some start date, and update the badge number accordingly.
UILocalNotification can't do this apparently. It looks like push notifications can, but I don't have a server component for this app, so using that as a workaround wouldn't work, and I'm not sure Apple would like it anyway.
I know there is some background app refresh updates in iOS7, but I'm not sure if they would work in this situation.
TLDR: How do I update a badge icon in iOS7 that requires a bit of calculation to get the correct number, on a weekly basis (or any arbitrarily long time basis)? And I want to do this background updating without a server component.
You simply schedule a silent local notification, with a nil message and then update the badge number. Also set the repeat count to nil otherwise the badge wont get updated if you call this local notification multiple times
This person posted a similar question, have a look
Related
I have to clear application badge icon while opening the application. I do clear by setting applicationBadgeIcon to 0.
=> But it clears my all notifications from notification center. I have also tried by setting applicationBadgeIcon to -1, But it also did not work for me.
Is ther Any solution?
UIApplication.shared.applicationIconBadgeNumber = 0 // Badge count was removed.
Its working fine for me in Swift 4
The thing you need to achieve will not possible if you pass the badge in payload of the push notification. If you any how achieve this behaviour then do one thing remove badge number from payload then you did not bother about to clear badge count and your push still display in notification
disadvantage:
1) user need to remove all notification one by one same like instagram
Otherwise there is no way to achieve this.
This question already has answers here:
How to detect push notification sent to other apps?
(2 answers)
Closed 6 years ago.
I'm working on an iOS game that has a score counter and some buttons at the top of the screen. When I receive any push notifications for a different app (e.g. a new email), the push notification covers the top of the screen for a few seconds, which is annoying when you're in the middle of a game. I would like to know whenever a third-party notification is being displayed, so that I can move the score counter and buttons below the push notification while it is being shown.
Is this possible?
Unfortunately, as of now (and probably forever) there is no API or way to interact with Apple's Notification Center, and thus it's impossible to know when a third-party notification is displaying. This is primarily because they strive to keep a consistent user experience across their entire platform at the developer's expense. The closest you can get is knowing when an application has left and entered the foreground (which will happen when they tap that notification) to properly pause the game
Thankfully, users can dismiss the alerts really quickly with a swipe of a thumb, but regardless, it's still annoying. Maybe make some small adjustments to your UI with this knowledge and have less user taps necessary at the top of the screen?
Good luck!
We want some callback to be triggered everyday at a fixed time even if our application is closed. I am new to IOS Swift and have not much idea about API's available.
I'm working on a project on iOS 7, 8 that use a lot of notifications (Remote, Local). I have some questions about Local Notification.
I'm using Local Notification to schedule an alarm or a count-down. As I know, the use of NSTimer is not really a good choice since it has only up to 10' in background & if the app process is killed it doesn't work anymore. Local Notification is managed by iOS but I have to accept its alert when the app is not in foreground. There's nothing like silent local notification (local notification without alert, sound or badge and app still knows about it although it's in background). Am I right ?
Let's assume that there're some simple local notifications in Notification Center, scheduled by our app. Normally when I touch on a notification to see it in my app, the others remain present until we interact with them. In some cases that I haven't figured out, all other notifications are removed from the Notification Center. Does anyone encounter this & understand why ?
I find the interactive notification feature in iOS very limited. I want to change the title of a defined UIMutableUserNotificationAction button & add an image for it, like I can do with UIButton. So the question is : Is it possible to customize the UI of an action button ?
Thanks for your help !
Unfortunately there is no correspondence in silent notification using local notifications.
The number of the visible notification in the notification center is a user decision, the user in Settings can decide to set a different number or decide to do not show them in notification center as well. As for the first point no. The third point is not clear, you can set the image you want for a remote just put in the payload the right name, local notifications use the app icon.
There is no silent notification for Local Notification. The user has to click to the notification to open your App.
I suppose that the associated application has deleted those notifications programmatically. Else, those notifications must stay in the notification center.
You cannot add image to action buttons but just the titles.
I tried more than two weeks to do the same. I had to show notification after 2 hrs even if the use doesn't click the notification. But the repetition facility is well handled in objective C. I could have created multiple local notification but it will also violates the total number of 64 notifications. Apple needs to improved the same.
So I've got a UILocalNotification setup to change the Icon badge.
[myNote setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]+1];
So it works fine if I don't change the badge number after I set it. If the badge shows 2, lets say, when I set the notification, it changes to 3 when the notification goes off. But lets say that I change it from 2 to 5 within the app before the notification fires, it still changes it to 3 when it does fire.
I need it to be able to add 1 to the current badge number, not the number that the badge showed when I first scheduled the notification. Ex: If it's 2 when I schedule the notification, then change it to 5 in the app, the notification should change it 6 when it does fire.
Is there a way to do it? I'm beginning to hate UILocalNotification.
Thanks guys!
Unfortunately, there is no such API. You can, however, discard all your previous notifications and reschedule them with the updated badge number. But I agree with you, local notifications and badge numbers are bound to reach a brick wall and annoy you.