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

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -