相关疑难解决方法(0)

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

直到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
查看次数

UserNotification在3天后重复每天/每小时 - iOS 10

UILocalNotification已被折旧,因此我想将我的代码更新为UserNotification框架:

let alertDays = 3.0
let alertSeconds = alertDays * 24.0 * 60.0 * 60.0

let localNotification:UILocalNotification = UILocalNotification()

localNotification.alertAction = "Reminder"
localNotification.alertTitle = "Reminder Title"
localNotification.alertBody = "Reminder Message"
localNotification.fireDate = Foundation.Date(timeIntervalSinceNow: alertSeconds)
localNotification.repeatInterval = .day            
UIApplication.shared().scheduleLocalNotification(localNotification)
Run Code Online (Sandbox Code Playgroud)

在等待初始通知后,如何使用UserNotification框架设置类似的每日或每小时重复?

let alertDays = 3.0
let alertSeconds = alertDays * 24.0 * 60.0 * 60.0

let content: UNMutableNotificationContent = UNMutableNotificationContent()

content.title = "Reminder Title"
content.subtitle = "Reminder Subtitle"
content.body = "Reminder Message"

let calendar = Calendar.current

let alarmTime = Foundation.Date(timeIntervalSinceNow: alertSeconds)
let …
Run Code Online (Sandbox Code Playgroud)

notifications date repeat swift ios10

8
推荐指数
1
解决办法
3174
查看次数

iOS 10 - 每隔"x"分钟重复一次通知

在iOS 10中,如何从特定日期/时间开始,在几分钟内设置本地通知重复.

例如,从9月8日上午11点开始,每15分钟触发一次本地通知?假设在下面,dateTimeReminder.date有09/08上午11点.

let dateStart = self.dateTimeNotif.date
let notifTrigger = UNCalendarNotificationTrigger.init(dateMatching: NSCalendar.current.dateComponents([.day, .month, .year, .hour, .minute], from: dateStart), repeats: true)
let notificationRequest = UNNotificationRequest(identifier: "MYNOTIF", content: notifContent, trigger: notifTrigger)

UNUserNotificationCenter.current().add(notificationRequest, withCompletionHandler: nil)
Run Code Online (Sandbox Code Playgroud)

使用上面的代码,我有可能在每个小时的特定时刻,每天的特定时刻安排,等等.但是如何将其变成"每"x"分钟"?任何帮助表示赞赏.

类似的问题 - 如何在iOS 10 UserNotifications上设置NSCalendarUnitMinute repeatInterval?

ios swift ios10

5
推荐指数
2
解决办法
8727
查看次数

UILocalNotification会在iOS 10上崩溃吗?

这是当前的UILocalNotification类,这是苹果刚刚在wwdc 16中宣布的iOS 10 UserNotification.

使用的旧应用程序UILocalNotification是否会在iOS 10上崩溃?

objective-c ios uilocalnotification swift ios10

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