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' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -