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

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -