UNNotificationSound не работает. в чем проблема?IOS

Программируем под IOS
Ответить
Anonymous
 UNNotificationSound не работает. в чем проблема?

Сообщение Anonymous »

импорт UIKit
импорт Awesome_notifications
импорт Shared_preferences_ios
импорт UserNotifications
@UIApplicationMain
class AppDelegate: FlutterAppDelegate {
var alertController: UIAlertController?

Код: Выделить всё

override func application(
_ application: 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(application)

NotificationCenter.default.addObserver(self, selector: #selector(appDidBecomeActive), name: UIApplication.didBecomeActiveNotification, object: nil)

createRepeatableNotificationWithCustomSound()
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}

@objc func appDidBecomeActive() {
print("App became active")
}

func requestNotificationAuthorization(_ application: UIApplication) {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound]) { granted, error in
DispatchQueue.main.async {
if let error = error {
print("Notification authorization error: \(error)")
return
}

if granted {
print("Notification authorization granted")
application.registerForRemoteNotifications()
} else {
print("Notification authorization denied")
}
}
}
}

func createRepeatableNotificationWithCustomSound() {
print("createRepeatableNotificationWithCustomSound called")
let content = UNMutableNotificationContent()
content.title = "Custom Sound Notification"
content.body = "This is a notification with a custom sound."

if let soundURL = Bundle.main.url(forResource: "new", withExtension: "aiff") {
print("Sound file found at path: \(soundURL.path)")
content.sound = UNNotificationSound(named: UNNotificationSoundName("new.aiff"))
} else {
print("Sound file not found: new.aiff")
}

let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats: true)

let request = UNNotificationRequest(
identifier: "RepeatableCustomSoundNotification",
content: content,
trigger: trigger
)

UNUserNotificationCenter.current().add(request) { error in
if let error = error {
print("Failed to add notification: \(error)")
} else {
print("Repeatable notification scheduled with custom sound.")
}
}
}
Я написал код в Deleate.swift, используя UNNotificationSound, как показано выше, но постоянно воспроизводится только звук iOS по умолчанию. В чем может быть проблема? При написании кода Dart зарегистрированный звук воспроизводится правильно, но когда звук удаляется и используется UNNotificationSound, зарегистрированный звук не воспроизводится, а воспроизводится только звук по умолчанию.

Подробнее здесь: https://stackoverflow.com/questions/792 ... he-problem
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»