swift - iOS locale notification pop-up doesn't appear -


i'm newbie in ios programming , in app i've uilocalenotification have appear @ time.

so first setup parameters :

let notificationsettings: uiusernotificationsettings! = uiapplication.sharedapplication().currentusernotificationsettings()      if (notificationsettings.types == uiusernotificationtype.none) {         var notificationtypes: uiusernotificationtype = uiusernotificationtype.alert | uiusernotificationtype.sound          // bouton d'envoi         var sendaction = uimutableusernotificationaction()         sendaction.identifier = "send"         sendaction.title = "send"         sendaction.activationmode = uiusernotificationactivationmode.foreground         sendaction.destructive = false         sendaction.authenticationrequired = true          // bouton de non-envoi         var dontsendaction = uimutableusernotificationaction()         dontsendaction.identifier = "dontsend"         dontsendaction.title = "don't send"         dontsendaction.activationmode = uiusernotificationactivationmode.background         dontsendaction.destructive = true         dontsendaction.authenticationrequired = false          let actionsarray = nsarray(objects: sendaction, dontsendaction)          var remindernotification = uimutableusernotificationcategory()         remindernotification.identifier = "remindernotification"         remindernotification.setactions(actionsarray [anyobject], forcontext: uiusernotificationactioncontext.minimal)          let categoriesforsettings = nsset(objects: remindernotification)          let newnotificationsettings = uiusernotificationsettings(fortypes: notificationtypes, categories: categoriesforsettings set<nsobject>)         uiapplication.sharedapplication().registerusernotificationsettings(newnotificationsettings)     } 

... , schedule notification :

var localnotification = uilocalnotification()     localnotification.firedate = nsdate(timeintervalsincenow: 3)     localnotification.timezone = nstimezone.defaulttimezone()     localnotification.alertbody = "hey, inform contacts !"     localnotification.alertaction = "send message"     localnotification.category = "remindernotification"     localnotification.soundname = uilocalnotificationdefaultsoundname      uiapplication.sharedapplication().schedulelocalnotification(localnotification) 

when try code, notifs displaying right in notification center, there no pop-up displayed... searched sources on net , don't understand why examples , tutos displaying pop-up because wrote same code...

thanks , have day !

edit : forgot : it's notification center have detect event, , not locale notification. want addobserver of notification center check event, possible in background state ?

according line: localnotification.firedate = nsdate(timeintervalsincenow: 3) want notification triggered 3 seconds later. assume app still in foreground when happens. if it's case, not have notification popup.

if app linked notification opened when notification received, has handle in appdelegate display custom popup.

func application(application: uiapplication!, didreceivelocalnotification notification: uilocalnotification!) {         // jobs here } 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -