Schedule local notification at specific times in Swift 2

I have been to all these forums and other sites, and I continue to receive pieces of the answer that do not add up. Essentially, I would like to create a notification that fires, for example, every weekday at 6:28, 12:28 and 17:28. I have pieces, but I'm really not sure where to go. Am I setting this right? Any help is appreciated.

let notification:UILocalNotification = UILocalNotification()
notification.category = "News and Sports"
notification.alertAction = "get caught up with the world"
notification.alertBody = "LIVE news and sports on VIC in just a minute!"
UIApplication.sharedApplication().scheduleLocalNotification(notification)
+4
source share
1 answer

Two basic steps are required to prepare local notifications:

Step 1

In iOS 8+, your application should ask and, subsequently, give the user permission to display local notifications. Request permission can be done as 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
}

registerUserNotificationSettings(_:), iOS 8. . , , Swift 2.

2

fireDate.

let notification:UILocalNotification = UILocalNotification()
...
... // set the notification category, alertAction, alertBody, etc.
...
notification.fireDate = ... // set to a future date
UIApplication.sharedApplication().scheduleLocalNotification(notification)

, @progrmr,

UILocalNotification. (. ), . repeatInterval .

. 64 . , , ( ).

. . (url?) Apple.

. , .

3 . 6:28, 12:28 17:28, . repeatInterval 3 .CalendarUnitWeekday.

+6

All Articles