Saturday, March 2, 2024
HomeiOS Developmentswift - My iOS app will not be in a position to...

swift – My iOS app will not be in a position to play sounds throughout Sleep Focus like different iOS app


Hello I’m making an alarm in my app, and this can not work if it doesn’t undergo Sleep focus mode to play a sound for the alarm. I’ve 3 examples of apps on the AppStore which have alarms, however don’t use time delicate alerts, or vital alerts (as confirmed by trying to the notification settings of those apps). They’re normally plain customary alerts, and managing to do one thing I’m not.

//occurs earlier in stream
func requestNotifications() {
UNUserNotificationCenter.present().requestAuthorization(choices: [.alert, .badge, .sound]) { _, _ in
}
}

` func setAlarm() {
UNUserNotificationCenter.present().getNotificationSettings { settings in
change settings.authorizationStatus {
case .licensed:
let middle = UNUserNotificationCenter.present()
middle.removePendingNotificationRequests(withIdentifiers: [“Alarm”])

            let content material = UNMutableNotificationContent()
            content material.interruptionLevel = .energetic //have additionally tried .timeSensitive with entitlement, although really feel I should not even have to do that judging from different apps
            content material.title = "Take a look at Title"
            content material.subtitle = "Take a look at subtitle"
             
            //this sound performs superb exterior of sleep focus
            content material.sound = UNNotificationSound(named: .init("Wakeup.mp3"))
            
            content material.categoryIdentifier = "alarm"
            
            let parts = Calendar.present.dateComponents([.hour, .minute], from: alarmTime)
            
            let set off = UNCalendarNotificationTrigger(dateMatching: parts, repeats: true)
            
            let request = UNNotificationRequest(identifier: "alarm", content material: content material, set off: set off)
             
            //deadly errors to be eliminated when going dwell
            middle.add(request) { (error) in
                if error != nil {
                  fatalError()
                } 
             }
        case .notDetermined: fatalError()
        case .denied, .provisional, .ephemeral: fatalError()
        @unknown default: fatalError()
        }
    }
}

`

I’ve spent days making an attempt to work out what I’m doing improper, however actually cannot inform, any assist can be appreciated (I truly even tried utilizing time delicate at one level and this did not assist).



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments