首页 文章

在特定的日期和时间安排本地通知

提问于
浏览
-1

如何在本地设备时间中午每周三和周六安排本地通知?

let localNoonSatNotification:UILocalNotification = UILocalNotification()
    localNoonSatNotification.userInfo = ["uid":"noonBreak"]
    localNoonSatNotification.alertAction = "Noon Break"
    localNoonSatNotification.alertBody = "Time for a break! Come and play few levels"
    localNoonSatNotification.fireDate = // get next Wednesday/Saturday 12:00 PM
    localNoonSatNotification.soundName = UILocalNotificationDefaultSoundName
    localNoonSatNotification.applicationIconBadgeNumber = 1
    UIApplication.sharedApplication().scheduleLocalNotification(localNoonSatNotification)

2 回答

  • 1

    你可以设置重复间隔,

    notification.repeatInterval = NSCalendarUnit.CalendarUnitWeekday
    

    希望这会有所帮助:)

  • 1

    如果有人仍然需要这个问题的帮助UNCalendarNotificationTrigger

    // Configure the recurring date.
    var dateComponents = DateComponents()
    dateComponents.calendar = Calendar.current
    
    dateComponents.weekday = 3  // Tuesday
    dateComponents.hour = 14    // 14:00 hours
    
    // Create the trigger as a repeating event.    
    let trigger = UNCalendarNotificationTrigger(
    dateMatching: dateComponents, repeats: true)
    

相关问题