Local Notification : repeat "permanently" with arbitrary alert message and incremental badge - iphone

I am working on the alert project which daily alerts the varying message and daily increments the badge. What I want to do is something like below.
Day1 : alert "January 1st", Badge = 1
Day2 : alert "January 2nd", Badge = 2
Day3 : alert "January 3rd", Badge = 3
Day4 : alert "January 4th", Badge = 4
::::
Day365 : alert "December 31st", Badge = 365
localnotification.repeatInterval = NSDayCalendarUnit
can repeat every day, but it will only repeats registered static notification. i.e always same alert message of "January 1st" and badge will stay "1" every time notification pops up.
I can register each separate local notifications but it is limited to register only 64 notifications, and it will not keep alerting after 64 times of alerts if the user does not launch the application at all.
Does any one know how to setup permanent snooze notification with arbitrary alert message and incremental badge without having launch the application? - If anyone knows workaround to do the same/similar thing will be great too!
Thank you so much for your help!

You can schedule a UILocalNotification to repeat it self, for example every day, week, month, year.... But it will be the same notification every time.
There is noway to make it snooze, you will need to set a second notification to make it look like the snooze time is past. Just cancel that notification when the user does open your app with the first notification.
The badge number is not incremented, it a stack number. You can not make it increment other then setting it when your app startup.

Related

OneSignal - Previously received notification is showing up again when app is opened next time

STR -
when notification receive dismiss from notification panel
close the app and don't use it for some time
open the app again
now will see the previously dismissed notification is showing up again.
shows previous past time of received notification. Example as 5h.
Expected result -
cleared notification from notification panel should not show when the app is opened next time.

Local Notification overrides previous local notification

I have a macOS Swift app where I am using local notifications. Here is a small methode for sending these:
func sendPushMessage(title: String, message: String, userInfo: [String:Any]) {
let notification: NSUserNotification = NSUserNotification()
notification.title = title
notification.informativeText = message
notification.userInfo = userInfo
notification.soundName = NSUserNotificationDefaultSoundName
notification.deliveryDate = Date()
self.center.scheduledNotifications = [notification]
}
This works for a long time and I have received all my notification (as well all notifications were shown in notification center). But actually the latest notification overrides the previous one. Let's say there is only one notification slot that always get overridenn with the latest notification.
In my notification center there is also only a single notification visible (the latest) instead of all received notifications. I have no idea when this "stops working" but I think one or two month ago? I am still on 10.13.6 high sierra.
The notification settings are correct.
I have no idea whatg I have done "wrong".
Fixed the issue by changing notification order (in notification settings) to manually by app and then it worked. After that I could change it back to newest and still working. Was only a bug in macOS for sure.
As refer documentation, you should set different identifier for each notification.
The identifier is unique to a notification. A notification delivered
with the same identifier as an existing notification replaces the
existing notification rather than causing the display of a new
notification.
You can set like that
notification.identifier = "yourIdentifier"

Using NSLocalNotification for multiple reminders

I am creating a reminder based app and my only problem right now is being able to implement reminders on my app.
Basically the user is presented with a UITableView where the user can add events and I'd like to fire these dates with a notification to the user reminding them of the event on a date saved to Core Data.
At this time, I still do not understand how NSLocalNotification works an I have heard some users here say how apple only allows 64 notifications to be processed at a time and I only managed to create 1 but when creating another event, It is down to 0 and randomly goes back to 1 event when I debug my app with the
UIApplication.sharedApplication().scheduledLocalNotifications?
and I can see the notification I set but not the other ones.
Any sample app in swift would greatly help me understand how I can set multiple notifications to add, edit, delete them.
Thanks in advance and happy coding
The easiest way to tackle this is to just create notifications and schedule them. If you want to remove specific notifications you will have to hold on to their references and persist them across app launches, however you can always remove all the currently scheduled notifications with UIApplication.sharedApplication().cancelAllLocalNotifications()
This is an example of scheduling a notification to fire once a day at the same time for 5 days:
let secondsInADay = 60 * 60 * 24
for i in 1...5 {
var dayString = "\(i) days"
if i == 1 {
dayString = "\(i) day"
}
let notification = UILocalNotification()
notification.fireDate = NSDate(timeInterval: Double(i * secondsInADay), sinceDate: NSDate())
notification.alertBody = "It has been \(dayString) since you last opened the app."
notification.soundName = UILocalNotificationDefaultSoundName
if notification.fireDate?.timeIntervalSinceNow > 0 {
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}
}
Also, you are correct, each app is given a queue for local notifications that have yet to fire. That queue can hold 64 individual notifications (a repeating notification counts as only 1 of those 64).

Show local notification for selected hours for everyday iphone sdk

I have developed application, I have successfully integrated the code of the local notification. Now I want is to show notification for selected hours only.
For example I want to show notification from 8:00 am to 8:00 pm every day every hours.
so how I can set repeat interval for this task.
Thanks in advance.
Satish
You can set the repeatInterval property of UILocalNotification.
To change the repeat interval or disable the notifications, I think your app will have to become active. For example, lets say you want to display the notifications from 8 AM to 8 PM. The 8 PM notification comes up but the user taps the 'close' button on the alert. In this case, I don't think anything can prevent the 9 PM notification from displaying unless your app becomes active between 8 & 9 PM.
In case the user does not close the notification & does come back to your app, you can check the current time & set the repeatInterval to 0 (don't repeat).
HTH,
Akshay

iPhone Local Notification loop: reset fireDate after device shows notification alert

after studying apple's "Local and Push Notifications in Depth" and loads of forum postings,
i still cannot figure this out:
my application schedules a notification in 10" at startup in didFinishLaunchingWithOptions.
if the app stays open, didReceiveLocalNotification is called after 10" and i can start another notification there. good.
if the app is in the background, the system alert pops up.
if i click "View", didReceiveLocalNotification is also called and i can schedule the next notification. good.
if i click "Close", nothing is called so far and i cannot renew the notification.
BAD.
i wonder, how i can capture the Close button event from the system's local notification alert popup.
any ideas?
TIA
dave
You cannot.
You can use recurring notification or schedule up to 64 for local notifications in advance and cancel/reschedule as needed.