Flutter iOS集成Spotify遇MissingPluginException,与后台服务插件冲突
Flutter iOS应用集成Spotify与flutter_background_service插件冲突问题
我使用免费Spotify账号开发,尝试将Flutter iOS应用与Spotify集成,代码在Android平台运行完全正常,但在iPhone上出现异常。已遵循《Spotify iOS SDK快速开始》中“配置iOS SDK”章节的步骤,应用能够成功连接Spotify、获取令牌、唤起应用并播放歌曲,也能点击底部按钮切换示例歌曲《I'll Make a Man Out of You》,但iOS上触发以下错误:
AppRemote: Connecting... [connection] nw_socket_handle_socket_event [C1.1.1:1] Socket SO_ERROR [61: Connection refused] AppRemote: Established a connection to the Spotify app. AppRemote: Authenticated with the Spotify app. AppRemote: Established a session with the Spotify app. flutter: \^[[38;5;12m┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────<…> flutter: \^[[38;5;12m│ #0 _SpotifyExampleState.setStatus (package:runwith/screens/SpotifyExample/Debugging.dart:647:13)<…> flutter: \^[[38;5;12m│ #1 _SpotifyExampleState.getAccessToken (package:runwith/screens/SpotifyExample/Debugging.dart:459:7)<…> flutter: \^[[38;5;12m├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄<…> flutter: \^[[38;5;12m│ 22:26:44.966 (+0:01:30.499038)<…> flutter: \^[[38;5;12m├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄<…> flutter: \^[[38;5;12m│ 💡 Got a token: BQDPjhNCDTPalqK71CNYU2PGI_VF8ejg7PzaQK7e01p2mnpi4smf7bX5SCANXUd211T84grf_DgcKKmuWN7KbOGPy-sKESYmgKG59_4EC0MKX21E6mZ9UVPaH58D4ovtKg33DJRU9FRJEWODFOISYGIUU09S328EWEYYWR802384WUDJUF98YCOIFIHSDJHCJ38EYIEDN90WEUF0UJDOFCJW09R0JFOIJU0R9U0rlumS_GSMx-OR0arQdE7ayy-OJxIDXCyPIZ8o0NlQtQdPwoJ7ZIxT4vzmNj4kj4JnbWxiy2V5v6NdMhUY8qYLk7YmZSdY2oL8CZe9oMOGQSoXR7cJA<…> flutter: \^[[38;5;12m└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────<…> ======== Exception caught by services library ====================================================== The following MissingPluginException was thrown while activating platform stream on channel player_state_subscription: MissingPluginException(No implementation found for method listen on channel player_state_subscription) When the exception was thrown, this was the stack: #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:313:7) <asynchronous suspension> #1 EventChannel.receiveBroadcastStream.<anonymous closure> (package:flutter/src/services/platform_channel.dart:662:9) <asynchronous suspension> ==================================================================================================== ======== Exception caught by services library ====================================================== The following MissingPluginException was thrown while activating platform stream on channel player_context_subscription: MissingPluginException(No implementation found for method listen on channel player_context_subscription) When the exception was thrown, this was the stack: #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:313:7) <asynchronous suspension> #1 EventChannel.receiveBroadcastStream.<anonymous closure> (package:flutter/src/services/platform_channel.dart:662:9) <asynchronous suspension> ====================================================================================================
核心错误为:MissingPluginException(No implementation found for method listen on channel player_state_subscription)MissingPluginException(No implementation found for method listen on channel player_context_subscription)
后续排查发现,flutter_background_service插件会破坏Spotify播放器状态流:停止后台服务时功能正常,但若在连接Spotify前启动后台服务则触发上述错误。现寻求两者共存的解决方案。
相关信息
依赖插件
dependencies: flutter: sdk: flutter # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 # ThirdParty Dependencies Added Manually shared_preferences: ^2.0.15 google_fonts: ^3.0.1 http: ^0.13.4 http_interceptor: ^1.0.2 dio: ^4.0.4 retrofit: ^3.0.0 flutter_datetime_picker: ^1.5.1 intl: ^0.17.0 fluttertoast: ^8.0.9 sn_progress_dialog: ^1.1.3 flutter_native_splash: ^2.2.14 flutter_launcher_icons: ^0.10.0 animated_splash_screen: ^1.3.0 country_code_picker: ^2.0.2 country_codes: ^2.2.0 animated_bottom_navigation_bar: ^1.1.0 carousel_slider: ^4.1.1 csc_picker: ^0.2.6 google_maps_flutter: ^2.2.0 location: ^4.4.0 permission_handler: ^9.2.0 path_provider: ^2.0.8 provider: ^6.0.1 flutter_polyline_points: 1.0.0 share_plus: ^4.0.4 flutter_background_service: ^2.4.5 device_info_plus: ^8.0.0 sensors_plus: ^2.0.1 image_picker: ^0.8.4+8 better_player: any flutter_google_places: 0.3.0 google_maps_webservice: ^0.0.19 google_api_headers: ^1.5.0 custom_marker: 1.0.0 pull_to_refresh: ^2.0.0 spotify_sdk: ^2.3.1 flutter_dotenv: ^5.0.2 cast: ^1.1.1 logger: ^1.1.0 flutter_vlc_player: ^7.1.4 app_settings: ^4.1.1 number_to_words: ^1.0.0 just_audio: ^0.9.31 webview_flutter: ^3.0.4 flutter_easyloading: ^3.0.5 flutter_html: ^3.0.0-alpha.6 just_the_tooltip: ^0.0.12 image: ^3.3.0 screenshot: ^1.3.0
Flutter Doctor输出
/Users/my_macbook_username/AndroidStudioProjects/flutter_v3.7.11/bin/flutter doctor --verbose [!] Flutter (Channel stable, 3.7.11, on macOS 13.3.1 22E261 darwin-arm64, locale en-PK) • Flutter version 3.7.11 on channel stable at /Users/my_macbook_username/AndroidStudioProjects/flutter_v3.7.11 ! The flutter binary is not on your path. Consider adding /Users/my_macbook_username/AndroidStudioProjects/flutter_v3.7.11/bin to your path. ! The dart binary is not on your path. Consider adding /Users/my_macbook_username/AndroidStudioProjects/flutter_v3.7.11/bin to your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision f72efea43c (3 weeks ago), 2023-04-11 11:57:21 -0700 • Engine revision 1a65d409c7 • Dart version 2.19.6 • DevTools version 2.20.1 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades. [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0) • Android SDK at /Users/exeideasmy_macbook_usernameLibrary/Android/sdk • Platform android-33, build-tools 33.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 14.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 14E222b • CocoaPods version 1.11.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2021.3) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866) [✓] Connected device (3 available) • SM A325F (mobile) • RF8R509QMYF • android-arm64 • Android 13 (API 33) • macOS (desktop) • macos • darwin-arm64 • macOS 13.3.1 22E261 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 112.0.5615.137 [✓] HTTP Host Availability • All required HTTP hosts are available ! Doctor found issues in 1 category. Process finished with exit code 0
目标平台与设备
- 系统版本:iOS 16.1、Android 13
- 设备:iPhone X、Samsung A32
开发环境
- 系统:Mac OS 13.3.1 (22E261)
- IDE:Android Studio Dolphin | 2021.3.1 Patch 1
内容的提问来源于stack exchange,提问作者Muhammad Hassan
相关产品推荐
相关产品推荐

