xcode - Schedule a local notification for a specific time in Swift 2 -


i've been on these forums , other sites , keep getting pieces of answer don't add up. essentially, create notification fires, example, every weekday @ 6:28 am, 12:28 pm, , 5:28 pm. have pieces i'm unsure go. setting right @ all? appreciated.

let notification:uilocalnotification = uilocalnotification() notification.category = "news , sports" notification.alertaction = "get caught world" notification.alertbody = "live news , sports on vic in minute!" uiapplication.sharedapplication().schedulelocalnotification(notification) 

preparing show local notifications requires 2 main steps:

step 1

on ios 8+ app must ask and, subsequently, granted permission user display local notifications. asking permission can done follows in appdelegate.

func application(application: uiapplication, didfinishlaunchingwithoptions launchoptions: [nsobject: anyobject]?) -> bool {     ...     if #available(ios 8, *) {         application.registerusernotificationsettings(uiusernotificationsettings(fortypes: [.sound, .alert, .badge], categories: nil))     }      return true } 

do not call registerusernotificationsettings(_:) when app running on pre-ios 8 operating system. otherwise, app crash @ runtime. luckily, shouldn't problem since you're working swift 2.

step 2

schedule notification @ future firedate.

let notification:uilocalnotification = uilocalnotification() ... ... // set notification's category, alertaction, alertbody, etc. ... notification.firedate = ... // set future date uiapplication.sharedapplication().schedulelocalnotification(notification) 

unfortunately, according this stack overflow answer @progrmr,

you cannot set custom repeat intervals uilocalnotification. has been asked before (see below) limited options provided. repeatinterval parameter enum type , limited specific values.

you cannot multiply enumerations , multiples of intervals. cannot have more 64 local notifications set in app. cannot reschedule notification once fires unless user chooses run app when notification fires (they may not run it).

there request repeat interval multipliers posted here. can add comments it. suggest filing bug report or feature request (url?) apple.

many other stack overflow answers confirm claims in quotes above. visit link full quoted answer, contains list of supporting answers.

a potential workaround case schedule 3 local notifications. set each 1 fire @ 6:28 am, 12:28 pm, , 5:28 pm, respectively. then, set repeatinterval of 3 local notifications .calendarunitweekday.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -