Reputation: 11
Local Notification only triggers once after device reboot. when i close and reopen the app it won't trigger even though i see it enters the function send() every time i run the app.
i have the trigger set to nil so it will trigger Imm . any ideas what am i getting wrong ?
Thank you so much O.K
import SwiftUI
import UserNotifications
@main
struct ozApp: App {
var body: some Scene {
WindowGroup {
ContentView().onAppear { send() }
}
}
func send(){
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { success, error in
if success {
print("All set!")
} else if let error = error {
print(error.localizedDescription)
}
}
let content = UNMutableNotificationContent()
content.title = "Message"
content.subtitle = "999"
content.sound = UNNotificationSound.default
let uuid = UUID().uuidString
let request = UNNotificationRequest(identifier: uuid , content: content, trigger: nil)
UNUserNotificationCenter.current().add(request)
}
}
Upvotes: 0
Views: 84