ios - Recurring local notifications using NSTimer don't work -


the user can select between couple of minute intervals in slider (3, 5, 8, 10 etc.).

since, not possible set recurring local notifications on custom time (only once in sec, minute, hour, day...).

i have created timer creates new local notification @ chosen time. weird thing here works on physical iphone 6 , iphone 5 simulator. not on physical iphone 5, running ios 9.3.2.

below code starts timer, number integer value fetched slider (3, 5, 8...):

@ibaction func savesettings(sender: anyobject) {     var timer = nstimer.scheduledtimerwithtimeinterval(double(number*60), target: self, selector: selector("sendnotification"), userinfo: nil, repeats: true)     print("notification interval set \(number)") }  func sendnotification() {     let localnotification = uilocalnotification()     localnotification.firedate = nsdate(timeintervalsincenow: double(number))     localnotification.alertbody = "this test body."     localnotification.timezone = nstimezone.defaulttimezone()     localnotification.soundname = uilocalnotificationdefaultsoundname      uiapplication.sharedapplication().schedulelocalnotification(localnotification) } 

it seem kind of hardware difference between iphone 5 , 6 affects solution. , can make work on both?

you need create uilocalnotification , schedule time intervals. , set firedate

notification.firedate(your_time_interval) uiapplication.sharedapplication.schedulelocalnotification(notification) 

something case nstimer

func sendnotificationnew() -> void {    let datetime = nsdate()    var notification = uilocalnotification()    notification.timezone = nstimezone.defaulttimezone()    notification.firedate(datetime)    notification.alertbody("test")   uiapplication.sharedapplication().schedulelocalnotification(notification) } 

or change code

@ibaction func savesettings(sender: anyobject) {     let datetime = nsdate().datewithtimeintervalsincenow(double(number*60))    var notification = uilocalnotification()    notification.timezone = nstimezone.defaulttimezone()    notification.firedate(datetime)    notification.alertbody("test")   uiapplication.sharedapplication().schedulelocalnotification(notification) } 

Comments

Popular posts from this blog

AbotX : How do you create a parallel crawler that stays on and can be added to at run time from new requests -

testing - Detect whether test has failed within fixture -

android - Create single AAR file from multiple modules using Gradle -