gdelataillade / alarm

A Flutter plugin to easily manage alarms on iOS and Android
https://pub.dev/packages/alarm
MIT License
132 stars 86 forks source link

AlarmException (PlatformException(NATIVE_ERR, [SwiftAlarmPlugin] Failed to load audio for asset #155

Closed tattuu closed 8 months ago

tattuu commented 9 months ago

Alarm plugin version 3.0.9 - 3.0.12: error 3.0.8: success

Describe the bug This error occurred suddenly.

I was using 3.0.11 successfully, but something kicked in and I started getting the error. The error occurs when locally stored audio data is set to AlarmSettings() and executed.

The following is a description of the error.

AlarmException (PlatformException(NATIVE_ERR, [SwiftAlarmPlugin] Failed to load audio for asset: /Users/hogehoge/Library/Developer/CoreSimulator/Devices/4046D12C-47CF-6I25-8C5D-D08036657C14/data/Containers/Data/Application/98SL602P-611D-4B95-8265-3FA762BC1AE6/Documents/xxx/yyy.mp3, null, null))

I tried it on the actual machine as well as on the simulator, but it was giving me errors. I have tried the latest version of XCode, deleted the simulator once, reinstalled it, deleted the application cache, and it still came up.

Then I dropped one version at a time and tried it, and it worked fine on 3.0.8.

So I have a feeling that the changes made between 3.0.8 and 3.0.9 are related.

To Reproduce I'm sorry, but I don't know how to reproduce this error, as I was able to use 3.0.11 fine, and then suddenly for some reason the error started appearing.

Information on flutter doctor is shown below.

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.0, on macOS 14.1.2 23B92 darwin-arm64, locale en-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] VS Code (version 1.86.2)
[✓] Connected device (3 available)            
[✓] Network resources

• No issues found!

Expected behavior Normal asset loading

Device info iPhone 15 Pro(simulator), iOS 17.2

Additional context I have tried everything and maybe there is a possibility that this package is not the cause.

If it is, I am sorry.

tattuu commented 9 months ago

In lib/src/ios_alarm.dart setAlarm(), it stops at line 59.

The following code throw AlarmException(e.toString());

gdelataillade commented 9 months ago

Hi @tattuu

Thanks for all the details. It is true that I recently made some changes regarding the asset audio import. I will investigate on that really soon.

gdelataillade commented 8 months ago

Hi @tattuu

Let's say this is the audio path stored locally on your iPhone:

/var/mobile/Containers/Data/Application/DB2234AF-EABE-4188-9F4A-0123456789/Documents/Audios/ringtone.mp3

You have to know that in the DB2234AF-EABE-4188-9F4A-0123456789 part is the Application's UUID. But each time you delete and reinstall or just update the app, a new UUID will be generated. Then it is safer to give as assetAudioPath just the relative path, which is in this case: Audios/ringtone.mp3. This way, it will always be true for each "versions" of the app.

Let me know if this is the reason of your errors.

Rest00rer commented 8 months ago

Hi @tattuu

Let's say this is the audio path stored locally on your iPhone:

/var/mobile/Containers/Data/Application/DB2234AF-EABE-4188-9F4A-0123456789/Documents/Audios/ringtone.mp3

You have to know that in the DB2234AF-EABE-4188-9F4A-0123456789 part is the Application's UUID. But each time you delete and reinstall or just update the app, a new UUID will be generated. Then it is safer to give as assetAudioPath just the relative path, which is in this case: Audios/ringtone.mp3. This way, it will always be true for each "versions" of the app.

Let me know if this is the reason of your errors.

Hello! I just checked and this is exactly the problem. Thank you

tattuu commented 8 months ago

Hi @gdelataillade

I tried it with the latest version 3.0.12 and it worked fine! As you say, it seems the UUID was misbehaving.

Thanks!😊

However, I think there will be many people like me who will continue to specify absolute paths to set up local files.

Therefore, it may be a good idea to include a note in the README regarding absolute path specifications, including UUID.