3

In my app, i have implemented functionality to check app version using bundleVersion String. Now, i want to run this function everyday at 8:00 a.m. This is kiosk based app which does not go into background. So, app would be active all the time.

I am using UILocalnotification to schedule a notification for that time. Now, my app has other UILocalnotification as well. I am not sure how can i identify notifications in app delegate didReceiveLocalNotification() method.

My method to schedule notification is below

func scheduleNotification() { //UIApplication.sharedApplication().cancelAllLocalNotifications() let notif = UILocalNotification() let calendar = NSCalendar.currentCalendar() let date = NSDate() var calendarComponents = NSDateComponents() calendarComponents = calendar.components([.Day,.Month,.Year], fromDate: date) let day = calendarComponents.day let month = calendarComponents.month let year = calendarComponents.year calendarComponents.day = day calendarComponents.month = month calendarComponents.year = year calendarComponents.hour = 8 calendarComponents.second = 0 calendarComponents.minute = 0 calendar.timeZone = NSTimeZone.systemTimeZone() let dateToFire = calendar.dateFromComponents(calendarComponents) notif.fireDate = dateToFire notif.timeZone = NSTimeZone.systemTimeZone() notif.repeatInterval = NSCalendarUnit.NSWeekdayCalendarUnit UIApplication.sharedApplication().scheduleLocalNotification(notif) } 

Any idea would be appreciated.

3

1 Answer 1

-1

Following method could help you to execute any task at regular interval , i used this method to call webservice at regular interval to provide searching functionality :

let debounceTimer : NSTimer? func test() { if let timer = debounceTimer { timer.invalidate() } debounceTimer = NSTimer(timeInterval: 0.3, target: self, selector: Selector("putmethodnamewhichneedstocall"), userInfo: nil, repeats: false) NSRunLoop.currentRunLoop().addTimer(debounceTimer!, forMode: "NSDefaultRunLoopMode") } 

For specific time daily Refer to this SO link :Repeating local notification daily at a set time with swift

Hope it helps.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for reply. I need to run function daily at 8:00 am. With NSTimer , i need to specify the interval. It wouldn't be feasible to give time interval.
updated code with reference link , use this to trigger timer accordingly

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.