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
Related
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).
Is it possible to have the lock screen pin/touchid to also authenticate my application if this is protected the same way using a pin/touchid? So I dont have to do this twice when opening an actionable notification.
Yes you can use home screen Passcode or TouchID to authenticate the app with in timeInterval by setting a property touchIDAuthenticationAllowableReuseDuration which is newly introduce in LocalAuthentication Framework in iOS9.
Code snippet(Example):-
let laContext = LAContext()
let timeInterval = 10 // In Seconds
LAContext.touchIDAuthenticationAllowableReuseDuration = timeInterval
......
......
If the device was successfully unlocked by TouchID/Passcode within this time interval, then Touch ID authentication on this context will succeed automatically and the reply block will be called without prompting user for Touch ID Authentication.
Note:- The Maximum supported interval is 5 minutes and setting the value beyond 5 minutes does not increase the accepted interval.
I have made local notification in iphone app. And set icon badge number.
All works good. But if i have two notification in tray and user clicks on clear button than notification deletes from tray.
But the badge number of icon remains same.
I want to set the badge number to zero.
Thanks.
use this in application didfinshlaunchingwithoptions
application.applicationIconBadgeNumber = 0;
For Swift3, you can clear badge number in your application didFinishLaunchingWithOptions with this line :
UIApplication.shared.applicationIconBadgeNumber = 0
You can used this line in anywhere in code if you want too.
What you want to achieve is only possible using the Server Notifications. You can not set badge number locally without opening the application. As you won't have any control when user clears the tray. There's no way you can set the badge count at that moment.
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.
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.