audio_service icon indicating copy to clipboard operation
audio_service copied to clipboard

AudioService.notificationClicked not working in iOS

Open VaibhavNeosoft opened this issue 2 years ago • 8 comments

(edit: Documentation request)

Documented behaviour

notificationClicked property A stream that broadcasts the status of the notificationClick event.

Actual behaviour

when the app is open from notification, the listener notificationClick is not receiving any update in iOS.

Minimal reproduction project

Official example: main.dart

Reproduction steps

  1. Run an example app on iOS
  2. Add a notificationClick listener to listen to the on-click updates
  3. Play an audio
  4. Click on the notification while the app is in the foreground/background
  5. notificationClick listener does not receive the update.

Output of flutter doctor

Checking Android licenses is taking an unexpectedly long time...[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.78.2)
[✓] Connected device (4 available)
[✓] HTTP Host Availability```
### Devices exhibiting the bug
iPhone SE, ios 16.4.1(a)

VaibhavNeosoft avatar Jun 01 '23 13:06 VaibhavNeosoft

This is an Android-only feature, but the documentation was not clear on that.

I have converted this into a documentation request rather than a bug report so that I can remember to correct the documentation.

ryanheise avatar Jun 01 '23 15:06 ryanheise

Is there anything that can be done to listen to the notification click on iOS?

VaibhavNeosoft avatar Jun 02 '23 05:06 VaibhavNeosoft

I am not aware of any, but if you are able to research and find a corresponding API on iOS, I could implement it for you.

ryanheise avatar Jun 02 '23 06:06 ryanheise

To determine whether a user has clicked on a notification in an iOS app, it is common to register a notification delegate, UNUserNotificationCenterDelegate, in the AppDelegate.swift file. By doing so, when a user interacts with a notification, the delegate receives an update and can trigger the necessary methods to notify the Flutter code about the notification click. This approach is typically used for regular notifications, but I am uncertain about its compatibility with Audio notification.

Upon reviewing your implementation in AudioServicePlugin.m, which contains native iOS code, I did not find a straightforward way to implement the above solution. I would like to know if there is a possibility of implementing the above solution within your existing implementation.

@ryanheise

VaibhavNeosoft avatar Jun 06 '23 06:06 VaibhavNeosoft

I am facing the similar issue, any update on this @ryanheise.

vishal-singh-22 avatar Aug 24 '23 10:08 vishal-singh-22

Upon reviewing your implementation in AudioServicePlugin.m, which contains native iOS code, I did not find a straightforward way to implement the above solution. I would like to know if there is a possibility of implementing the above solution within your existing implementation.

Yes, I think so.

The AppDelegate.switch file or the AppDelegate.m file is not part of the plugin, it is part of your app. So it would just require adding iOS setup instructions to the README guiding app developers on how to configure this file.

Here is another iOS plugin that takes a similar approach:

https://pub.dev/packages/background_downloader

ryanheise avatar Aug 24 '23 12:08 ryanheise

Hi, When playing in the background, I click the playback control in the notification bar to enter the foreground. Which event can be monitored? Thank you.

zhanglijie5997 avatar Jun 13 '24 02:06 zhanglijie5997

Is there anything that can be done to listen to the notification click on iOS?

Hello @VaibhavNeosoft
Have you found any solution to resolve this?

Nehal-1234 avatar Jan 29 '25 05:01 Nehal-1234