相关疑难解决方法(0)

如何跳过第一次出现的重复UNCalendarNotificationTrigger?

说今天是星期一,下午1点.我想从今天下午2点开始,从我的iOS应用程序安排每周本地通知.我这样做:

NSDateComponents *components = [[[NSDateComponents alloc]init]autorelease];
components.weekday = 2;
components.hour = 14;
components.minute = 0;

UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components repeats:YES];
//then make a UNMutableNotificationContent and UNNotificationRequest and schedule it
Run Code Online (Sandbox Code Playgroud)

但如果我想在下周一下午2点开始,我该如何跳过第一次?

要以另一种方式提出问题,如何UNCalendarNotificationTrigger在某个任意时间安排重复开始,而不是第一次出现重复间隔?

ios usernotifications

12
推荐指数
1
解决办法
866
查看次数

如何在用户通知中设置重复频率

直到iOS 9我们写local notifications这样的

UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = pickerDate;
localNotification.alertBody = self.textField.text;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.repeatInterval = NSCalendarUnitMinute;
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
Run Code Online (Sandbox Code Playgroud)

我们在本地通知中repeatInterval,现在在WWDC2016Apple宣布User Notification其中包含

  • UNTimeIntervalNotificationTrigger.
  • UNCalendarNotificationTrigger.

    UNTimeIntervalNotificationTrigger* trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:60 repeats:YES];
    
    Run Code Online (Sandbox Code Playgroud)

上面的代码会在每分钟后触发通知.但无法设定日期.

NSDateComponents* date = [[NSDateComponents alloc] init];
date.hour = 8;
date.minute = 30;

UNCalendarNotificationTrigger* triggerC = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:date repeats:YES];
Run Code Online (Sandbox Code Playgroud)

上面的代码可以设置,重复将在明天8:30触发,而不是在分钟后.

在iOS 10中User Notification我如何设置重复频率的日期时间就像我们可以设置的一样UILocalNotification

我希望 …

objective-c nsdate nsdatecomponents ios uilocalnotification

9
推荐指数
1
解决办法
3861
查看次数

设置重复本地通知的日期

我想设置从日期开始重复的本地通知。例如:

开始日期:2018 年 6 月 25 日

今天日期:2018 年 6 月 21 日

我被困在这里了。下面的代码可以工作,但它从今天开始而不是从 2018 年 6 月 25 日开始触发本地通知。

请看一下我的本地通知功能:

func scheduleDosageLocalNotification(date: Date) {

        reminder.dosageIdentifier = "Dosage_Day"

        var calendar = Calendar.current
        calendar.timeZone = TimeZone.current

        let notificationContent = UNMutableNotificationContent()
        // Configure Notification Content
        notificationContent.title = "DOSAGE REMINDER"
        notificationContent.body = "Remember to take your TEST tablet dialy."

        // Set Category Identifier
        notificationContent.categoryIdentifier = Notification.Category.First
        var components = calendar.dateComponents([.hour, .minute], from: date)

        components.hour = 08
        components.minute = 00


        let notificationTrigger = UNCalendarNotificationTrigger(dateMatching: …
Run Code Online (Sandbox Code Playgroud)

ios uilocalnotification swift

5
推荐指数
1
解决办法
2908
查看次数

每周触发通知Swift 3

我正在努力制定一个时间表,在这个时间表中,我需要记住我在星期一特定时间上课的所有周.问题是如果我在打印变量triggerWeekly时指定工作日= 1(星期日),它会告诉我工作日= 2,所以通过执行测试我没有收到这样的通知.我需要知道为什么会这样

let weekday = 1 //Sunday 19 Mar 
let calendar = NSCalendar.current
var date = DateComponents()
date.weekday = weekday
date.hour = 1
date.minute = 5

let ultimateDate = calendar.date(from: date)

let triggerWeekly = Calendar.current.dateComponents([.weekday, .hour, .minute], from:
ultimateDate!)

print(triggerWeekly) // hour: 1 minute: 5 second: 0 weekday: 2 isLeapMonth: false 
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerWeekly, repeats: true)
let identifier = "curso\(String(Index))"
let request = UNNotificationRequest(identifier: identifier,
                                        content: content, trigger: trigger)
Run Code Online (Sandbox Code Playgroud)

notifications calendar weekday swift3

2
推荐指数
1
解决办法
2008
查看次数