swift2 - Actions buttons not showing up in local notifications ios 9.2 swift 2 -


i creating notifications in loop, relevant code is:

func application(application: uiapplication, didfinishlaunchingwithoptions launchoptions: [nsobject: anyobject]?) -> bool {     appdelegate = self      sernotificationtype = uiusernotificationtype.alert.union(uiusernotificationtype.sound).union(uiusernotificationtype.badge)      let completeaction = uimutableusernotificationaction()     completeaction.identifier = "complete" // unique identifier action     completeaction.title = "clear" // title action button     completeaction.activationmode = .background // uiusernotificationactivationmode.background - don't bring app foreground     completeaction.authenticationrequired = false // don't require unlocking before performing action     completeaction.destructive = true // display action in red      let callinaction = uimutableusernotificationaction()     callinaction.identifier = "callin"     callinaction.title = "call now"     callinaction.destructive = false     callinaction.authenticationrequired = false     callinaction.activationmode = uiusernotificationactivationmode.background      callinaction.destructive = false      let notificationcategory = uimutableusernotificationcategory() // notification categories allow create groups of actions can associate notification     notificationcategory.identifier = "callinnotification"     notificationcategory.setactions([callinaction, completeaction], forcontext: .default) //uiusernotificationactioncontext.default (4 actions max)     notificationcategory.setactions([completeaction, callinaction], forcontext: .minimal) //uiusernotificationactioncontext.minimal - when space limited (2 actions max)     application.registerusernotificationsettings(uiusernotificationsettings(fortypes: notificationtypes, categories: nsset(array:[notificationcategory]) as? set<uiusernotificationcategory>))      return true } 

scheduling of notifications done in loop (and maybe reason wrong scheduling):

func schedulelocalnotifications() {      let arrayofevents: [[meeting]] = calendarcontroller.sharedinstance.getallmeetings()      //remove callin notifications anyway     self.removeschedulednotifications()          var limitcounter = 0  //limit 64 local notifications          print("scheduling start: \(callin.settings.notifynumberofminutesbeforeevent)")         var x = 0; x < arrayofevents.count; x++ {          var y = 0; y < arrayofevents[x].count; y++ {             let event = arrayofevents[x][y]              if(event.starttime.timeintervalsincedate(nsdate()) > -2000 && limitcounter <= 64){                 if(notificationsareallowed()){                     let notification = uilocalnotification()                     let minutesbefore = callin.settings.notifynumberofminutesbeforeevent                     notification.firedate = event.starttime.datebyaddingtimeinterval(-minutesbefore * 60) //time of launch of notification                      if(minutesbefore <= 1){                         notification.alertbody = "your \(event.title) start"                     }else{                         notification.alertbody = "you have \(event.title) in \(int(minutesbefore)) minutes"                     }                     notification.alertaction = "ok"                     notification.soundname = uilocalnotificationdefaultsoundname                     notification.userinfo = ["title": event.title, "uuid": event.uuid, "callin": "callinnotification"]                     notification.category = "callinnotification"                     notification.applicationiconbadgenumber = 1                      uiapplication.sharedapplication().schedulelocalnotification(notification)                 }                  limitcounter += 1             }         }     } } 

the buttons call now, , dismiss not showing up. want this: enter image description here

what this: enter image description here

ok, found problem , may useful in future:

i had

uiapplication.sharedapplication().registerusernotificationsettings(notificationsettings) 

was called twice in 2 different places in application (because had setting in application, , needed alter settings page). when refactored, , called once, worked.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -