I just want to send a local notification at 11:55 am Monday, Tuesday, Wednesday, Thursday and Friday. I couldn't find a detailed source. Can you help me?
Asked
Active
Viewed 272 times
-1
-
do you mean using APNs ? – Mohmmad S Jan 14 '19 at 10:26
-
@7bebMrto Sorry. I want to send local notifications. – Umut Can Alparslan Jan 14 '19 at 10:47
-
First of all, please read https://developer.apple.com/documentation/usernotifications. Regarding local notifications this article should help: https://developer.apple.com/documentation/usernotifications/scheduling_a_notification_locally_from_your_app – D. Mika Jan 14 '19 at 11:19
-
@D.Mika dateComponents.weekday = 3 So how do I do this for more than one day. – Umut Can Alparslan Jan 14 '19 at 11:36
-
1@Umut Can Alparslan: AFAIK you have to create a UNCalendarNotificationTrigger and a UNNotificationRequest for each weekday. – D. Mika Jan 14 '19 at 11:39
-
possible duplicate of https://stackoverflow.com/a/42892780/2303865 – Leo Dabus Jan 14 '19 at 13:51
1 Answers
1
You can use UNCalendarNotificationTrigger
and create a trigger. You can set date, timezone, year, month, day, hour, minute and if need repeat or not.
Next, create a request UNNotificationRequest
, and finish adding the request to Notification Center.
Like this:
import UserNotifications
let trigger = UNCalendarNotificationTrigger(dateMatching: DateComponents(calendar: Calendar.current, timeZone: Calendar.current.timeZone, year: 2019, month: 1, day: 14, hour: 11, minute: 55, repeats: true )
let request = UNNotificationRequest(identifier: "identifier", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
You can create (schedule) only 64 local notifications

Lailan Matos
- 125
- 5