ios - How to make a daily notification at 8 am? (Swift 3) -


i'm sorry ask that, i've tried in 5 different ways , none of them worked. i'm working on app gives everyday, when awake, little notification interesting fact. takes facts array set. i've tried use unnotificationcenter, uilocalnotification, etc. didn't succeed in writing function. glad if me out code!

so, @ 8 am, app has to

  1. call function gives new fact array , store in userdefaults, lets call newfact()
  2. make notification appears on 8 every day, if phone locked

i thankful if me!

use below code

you can call function here

let fact = self.newfact() userdefaults.standard.set(fact,forkey: "fact")   var datecomp:nsdatecomponents = nsdatecomponents()             datecomp.year = 2017;             datecomp.month = 04;             datecomp.day = 05;             datecomp.hour = 08;             datecomp.minute = 00;             datecomp.timezone = nstimezone.systemtimezone()          var calender:nscalendar = nscalendar(calendaridentifier: nscalendaridentifiergregorian)!         var date:nsdate = calender.datefromcomponents(datecomp)!          var notification:uilocalnotification = uilocalnotification()         notification.category = "daily alarm "         notification.alertbody = fact         notification.firedate = date         notification.repeatinterval = nscalendarunit.calendarunitday 

Comments