Thank you for the advice!Now I find the issue: the notification is not coming if the app is open (in foreground) when it should come.So if I cklick on home button after activate the notification it works. But unfortunately having the app in foreground stops the notification for ever. So it is not delivered it I quit the app...
Post
Replies
Boosts
Views
Activity
Error is "nil". (Even though I allowed notifications first time)Additionally I get this error in the console as soon as my app is running:invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidMode to debug. This message will only appear once per execution.If I quit the app with swipe from bottom to top (iPhone 11 Simulator) I get the error code like I get with the timer. So it seems like the trigger is not working correctly:Can't end BackgroundTask: no background task exists with identifier 1 (0x1), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.I tried the same code in a macOS App and there it works... very strange...
My current code is the following://Asking for permissions
let center = UNUserNotificationCenter.current()
print("Authorizsation:")
center.requestAuthorization(options: [.alert, .sound]) { granted, error in
print("Error")
}
//create the notification
let content = UNMutableNotificationContent()
content.title = "Hello"
content.body = "30 Sec are over"
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: (30), repeats: true)
// Create the request
let uuidString = UUID().uuidString
let request = UNNotificationRequest(identifier: uuidString,
content: content, trigger: trigger)
// Schedule the request with the system.
//let notificationCenter = UNUserNotificationCenter.current()
center.add(request) { (error) in
if error != nil {
print("Error2: \(error)")
}
}Bad thing is that nothing happens...In console I can see:Authorizsation:ErrorFor testing I implement it in an action of a button. In future it should starts automatically with viewDidLoad() or applicationDidEnterBackground() or (much better) a system function after the iPhone is booting.Do you have any further ideas?
Thank you. So do I need both notification triggers or is one enough? If there is a choice I would prefer the interval notification trigger. (Listening also shows what I want). Do I need to create a new class for this or can I use a specific function? Remember the trigger should starts if application enters background... Thanks again!
Sry for the late reply.Yes it's actually a local notification. There is no web service needed.The only thing the application wants to do in background, is to wait for 30 minutes and then send a notification. If you tap on the notification the user should be navigated into the app and all other steps are inclued there.