ios - Why I get multiple UILocalNotifications in Swift? -


this function:

func sendnotificationevery() {     print("hey!")     notification.alertbody = "message here" // text displayed in notification     notification.firedate = nsdate()  // right (when notification fired)     notification.soundname = uilocalnotificationdefaultsoundname // play default sound      notification.repeatinterval = nscalendarunit.minute // line defines interval @ notification repeated     notification.applicationiconbadgenumber = 1     uiapplication.sharedapplication().schedulelocalnotification(notification) } 

and call here:

override func viewwilldisappear(animated: bool) {     sendnotificationevery() } 

so, issue is: when close app send 3-4 notifications instead of 1. how can fix issue? , want know, why happens?

first of all, imagine requirement "while closing app have show notification".

as per this, instead of writing above code in viewwilldisappear, write in appdelegate class, - (void)applicationdidenterbackground:(uiapplication *)application method.

this solve problem.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -