相关疑难解决方法(0)

如何在iOS 10 UserNotifications上设置NSCalendarUnitMinute repeatInterval?

在UILocalNotification我们使用NSCalendarUnitMinute像重复.....但我在iOS 10 UserNotification doc中找不到...我怎样才能NSCalendarUnitMinute在iOS 10中使用类似的重复UserNotification

这是代码,它将在晚上8:30安排本地通知,并在每一分钟后重复.

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)

objective-c ios swift ios10 unnotificationrequest

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

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

安排本地通知每天从明天开始在Swift中重复

我正在尝试安排每天(在特定时间,但从明天开始)触发本地通知。

即“从明天起每天晚上8点触发通知”

我一直在使用这个 SO问题作为指导,我相信我正在按照它说的做,但是今天当我运行以下代码时(如果我将通知安排在晚上8点之前),我仍然会收到通知:

    func testDateNotification(){

    let content = UNMutableNotificationContent()
    content.title = "Test"
    content.body = "This is a test"
    let tomorrow = Calendar.current.date(byAdding: .day, value: 1, to: Date())

    let userCalendar = Calendar.current
    var components = userCalendar.dateComponents([.hour, .minute], from: tomorrow!)

    components.hour = 20
    components.minute = 00


    let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: true)
    let request = UNNotificationRequest(identifier: "test", content: content, trigger: trigger)

    UNUserNotificationCenter.current().add(request) { (error) in
        if ((error) != nil){
            print("Error \(String(describing: error))")
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

ios uilocalnotification swift unnotificationtrigger

6
推荐指数
1
解决办法
2721
查看次数