AutorÃa | Ultima modificación | Ver Log |
//// LocalNotificationManager.swift// twogetskills//// Created by Efrain Yanez Recanatini on 8/7/22.//import Foundationimport SwiftUIclass LocalNotificationManager {init() {UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error inif granted == true && error == nil {print("Notifications permitted")} else {print("Notifications not permitted")}}}func sendNotification(title: String, subtitle: String?, body: String, launchIn: Double) {let content = UNMutableNotificationContent()content.title = titleif let subtitle = subtitle {content.subtitle = subtitle}content.body = bodylet imageName = "logo"guard let imageURL = Bundle.main.url(forResource: imageName, withExtension: "png") else { return }let attachment = try! UNNotificationAttachment(identifier: imageName, url: imageURL, options: .none)content.attachments = [attachment]let trigger = UNTimeIntervalNotificationTrigger(timeInterval: launchIn, repeats: false)let request = UNNotificationRequest(identifier: Constants.NOTIFICATION_TRIGGER_NAME, content: content, trigger: trigger)UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)}}