import UIKit
import awesome_notifications
import shared_preferences_ios
import UserNotifications
@UIApplicationMain
class AppDelegate: FlutterAppDelegate {
var alertController: UIAlertController?
override func utility(
_ utility: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
GeneratedPluginRegistrant.register(with: self)
SwiftAwesomeNotificationsPlugin.setPluginRegistrantCallback { registry in
SwiftAwesomeNotificationsPlugin.register(
with: registry.registrar(forPlugin: "io.flutter.plugins.awesomenotifications.AwesomeNotificationsPlugin")!)
FLTSharedPreferencesPlugin.register(
with: registry.registrar(forPlugin: "io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin")!)
}
requestNotificationAuthorization(utility)
NotificationCenter.default.addObserver(self, selector: #selector(appDidBecomeActive), title: UIApplication.didBecomeActiveNotification, object: nil)
createRepeatableNotificationWithCustomSound()
return tremendous.utility(utility, didFinishLaunchingWithOptions: launchOptions)
}
@objc func appDidBecomeActive() {
print("App grew to become lively")
}
func requestNotificationAuthorization(_ utility: UIApplication) {
UNUserNotificationCenter.present().requestAuthorization(choices: [.alert, .sound]) { granted, error in
DispatchQueue.most important.async {
if let error = error {
print("Notification authorization error: (error)")
return
}
if granted {
print("Notification authorization granted")
utility.registerForRemoteNotifications()
} else {
print("Notification authorization denied")
}
}
}
}
func createRepeatableNotificationWithCustomSound() {
print("createRepeatableNotificationWithCustomSound known as")
let content material = UNMutableNotificationContent()
content material.title = "Customized Sound Notification"
content material.physique = "This can be a notification with a customized sound."
if let soundURL = Bundle.most important.url(forResource: "new", withExtension: "aiff") {
print("Sound file discovered at path: (soundURL.path)")
content material.sound = UNNotificationSound(named: UNNotificationSoundName("new.aiff"))
} else {
print("Sound file not discovered: new.aiff")
}
let set off = UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats: true)
let request = UNNotificationRequest(
identifier: "RepeatableCustomSoundNotification",
content material: content material,
set off: set off
)
UNUserNotificationCenter.present().add(request) { error in
if let error = error {
print("Failed so as to add notification: (error)")
} else {
print("Repeatable notification scheduled with customized sound.")
}
}
}
}
I wrote the code in delegate.swift utilizing UNNotificationSound as proven above, however solely the default iOS sound retains enjoying repeatedly. What might be the issue? When written in Dart code, the registered sound performs appropriately, however when the sound is deleted and UNNotificationSound is used, the registered sound doesn’t play, and solely the default sound performs.