Создание еженедельных быстрых локальных уведомлений ios - PullRequest
0 голосов
/ 02 июля 2018

Я могу создавать ежедневные уведомления, но не еженедельные, используя фреймворк swift 3 ios 10 User Notification. Daily работает нормально, но когда я добавляю параметр .weekday, он не отправляет мне уведомление.

Код:

        for i in 1 ... 7
        {
            let center =  UNUserNotificationCenter.current();

            let content = UNMutableNotificationContent();
            content.title = "Title";
            content.body = "content";

            content.sound = UNNotificationSound.default();

            var dateComponents = DateComponents();

            dateComponents.weekday = i;

            // hours is 00 to 11 in string format
            if (daynight == "am")
            {
                dateComponents.hour = Int(hours);
            }
            else
            {
                dateComponents.hour = Int(hours)! + 12;
            }

            // mins is 00 to 59 in string format
            dateComponents.minute = Int(mins);
            dateComponents.second = 0;

            let date = Calendar.current.date(from: dateComponents);

            // tiriggerDaily works without weekday for daily but adding weekday doesn't make it weekly                                
            let triggerDaily = Calendar.current.dateComponents([.weekday, .hour, .minute, .second], from: date!);
            let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDaily, repeats: true);


            let identifier = // a uuid;
            let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger);

            center.add(request, withCompletionHandler:
            {
                (error) in

                if let error = error
                {
                    // Error happened
                    print("Error: ");
                    print(error);
                }
            });

Нужно получить код, чтобы выяснить еженедельно. Использовал это как руководство: https://useyourloaf.com/blog/local-notifications-with-ios-10/

Пример того, что я хочу, это:

A user selects Monday, 11:25pm and it is a Monday at 11:23pm.
Then the user should get a notification in two minutes plus one the following week and so on.

Некоторые другие заметки / вопросы:

1. Do you have to wait a week for weekly notifications to start? Like in the example above will it start the following week?

Просто мысль, потому что я пока не могу все сделать правильно.

...