Я использую Swift 4.2.xcode 10, пожалуйста, у меня возникли проблемы с уведомлением, которое я использовал локально, но обнаружил, что оно повторяется не точно в неправильный день, а иногда со временем дублирования
Я пытаюсь заставить локальное уведомление повторяться раз в неделю, поэтому я использовал как яблокоговорит
dateComponents.weekday = 6 // Friday >>>>> this is not worke
dateComponents.hour = 14 // 14:00 hours >>> working good
dateComponents.minute = 59 // 14:00 hours . >>> working good
поэтому, когда я ставлю dateComponents.weekday = any number
, предполагая, что
1 = воскресенье 2 = понедельник
3=`tuesday`
4=wednesday
5=thursday
6= friday
7=saturday
но как янапишите уведомление обнаружилось в день разницы, чем я положил
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let center = UNUserNotificationCenter.current()
let options: UNAuthorizationOptions = [.alert, .sound];
center.requestAuthorization(options: options) { (granted, error) in
if !granted {
print("Something went wrong")
}
}
center.getNotificationSettings { (settings) in
if settings.authorizationStatus != .authorized {
// Notifications not allowed
}
}
let content = UNMutableNotificationContent()
content.title = "test"
content.body = "test hello "
content.sound = UNNotificationSound.default()
// let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 300, repeats: false)
var dateComponents = DateComponents()
dateComponents.calendar = Calendar.current
// dateComponents.day = 3
dateComponents.weekday = 6 // Friday
dateComponents.hour = 14 // 14:00 hours
dateComponents.minute = 59 // 14:00 hours
let trigger = UNCalendarNotificationTrigger(
dateMatching: dateComponents, repeats: true)
let uuidString = UUID().uuidString
let request = UNNotificationRequest(identifier: uuidString,
content: content, trigger: trigger)
// Schedule the request with the system.
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.add(request) { (error) in
if error != nil {
// Handle any errors.
}
}
return true
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}