unusernotificationcenter

Removing scheduled local notification

别等时光非礼了梦想. 提交于 2021-01-28 23:41:26
问题 I know there are plenty of similar questions and answers, and I reviewed them all, but still cannot find the solution. Despite of removing a scheduled notification from UNUserNotificationCenter it still gets triggered. I create local notification as follows: let aDF = DateFormatter() aDF.dateFormat = "yyyy-MM-dd HH:mm:ss" var identifierST = "" if update == true { identifierST = myCoreDataEntity.notificationUID! } else { identifierST = aDF.string(from: Date()) } let notif =

Removing scheduled local notification

人盡茶涼 提交于 2021-01-28 22:38:08
问题 I know there are plenty of similar questions and answers, and I reviewed them all, but still cannot find the solution. Despite of removing a scheduled notification from UNUserNotificationCenter it still gets triggered. I create local notification as follows: let aDF = DateFormatter() aDF.dateFormat = "yyyy-MM-dd HH:mm:ss" var identifierST = "" if update == true { identifierST = myCoreDataEntity.notificationUID! } else { identifierST = aDF.string(from: Date()) } let notif =

how to set local notifications between 8am and 8pm every day

白昼怎懂夜的黑 提交于 2020-07-08 03:19:14
问题 So I am very new to Swift and I'm currently setting a repeating timer every 30 min after the app was launched, but i would like to only send notification between 8 am and 8 pm. Is it possible to do this without setting a reminder for each specific time? This is how I'm currently doing this. override func viewDidLoad(){ let notificationCenter = UNUserNotificationCenter.current() notificationCenter.requestAuthorization(options: [.alert, .sound]) { (granted, error ) in // enable or disable if

how to set local notifications between 8am and 8pm every day

∥☆過路亽.° 提交于 2020-07-08 03:17:01
问题 So I am very new to Swift and I'm currently setting a repeating timer every 30 min after the app was launched, but i would like to only send notification between 8 am and 8 pm. Is it possible to do this without setting a reminder for each specific time? This is how I'm currently doing this. override func viewDidLoad(){ let notificationCenter = UNUserNotificationCenter.current() notificationCenter.requestAuthorization(options: [.alert, .sound]) { (granted, error ) in // enable or disable if

`UNTimeIntervalNotificationTrigger` repeats: true only fired once. macOS bug? Works on iOS

霸气de小男生 提交于 2020-06-01 05:48:06
问题 I want a notification to show every 60 seconds. It only happened once on MacOS. The same exact code works normally on iOS. If I manually remove the notification from macOS notification center, it'll eventually show again. So the problem seems like notification won't show again if it's already showed once and the user didn't take any action. Did I miss something obvious here? Current macOS: 10.15.4 Current iOS: 13.4.1 on App Delegate func userNotificationCenter(_ center:

How to call a function when the app is inactive (e.g. playing music in background)?

时光毁灭记忆、已成空白 提交于 2020-04-07 08:25:29
问题 I am making a music-streaming alarm clock. Music streams for the duration selected by the user, including in the background, and at the end of the duration a custom alarm sound is played in addition to a local notification. In short (1) set timer (2) local notification fires off (3) streamed music stops (4) alarm plays I am able to do (1) and (2) ok, but am unable to figure out how to trigger (3) or (4) when the app is in the background. Here is the code for (1) and (2) let center =

Swift Repeat LocalNotification every 5 days

 ̄綄美尐妖づ 提交于 2020-03-23 04:35:24
问题 How to repeat LocalNotification every 5 days at 10:00 AM I try this, but it's not working let content = UNMutableNotificationContent() content.title = "Hello!" content.body = "Hello_message_body" content.sound = UNNotificationSound.default() let futureTime = Date().addingTimeInterval(5 * 24 * 60 * 60) var calendar = NSCalendar.current calendar.timeZone = NSTimeZone.system var components = calendar.dateComponents([.hour, .minute, .second], from: futureTime) components.hour = 10 components

Why userNotificationCenter didReceive is not fired?

萝らか妹 提交于 2020-02-03 01:52:48
问题 This is a part of my code. I want to use UNUserNotificationCenter and UNUserNotificationCenterDelegate to handle notification events. This code catches the notification event when the app is in a foreground state. But "didReceive" is not fired for a background state. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { UNUserNotificationCenter.current().delegate = self application

Why userNotificationCenter didReceive is not fired?

蓝咒 提交于 2020-02-03 01:51:32
问题 This is a part of my code. I want to use UNUserNotificationCenter and UNUserNotificationCenterDelegate to handle notification events. This code catches the notification event when the app is in a foreground state. But "didReceive" is not fired for a background state. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { UNUserNotificationCenter.current().delegate = self application

UNUserNotificationCenter didReceive response not called when app is terminated

て烟熏妆下的殇ゞ 提交于 2020-01-14 18:56:37
问题 I'm working on local notifications but the problem I have is that the method didReceive Response is not being called when the app is terminated so when I tap on a notification action it just launches the app and did nothing else. But when the app is just in the background everything works as usual. Anything wrong with my code? //MyClassNameViewController.swift override func viewDidLoad() { super.viewDidLoad() UNUserNotificationCenter.current().delegate = self } func triggerAlarm1() { //