在 Flutter 中“接收共享意图”在 IOS 中未收到任何值

Sam*_*n S 7 swift flutter flutter-getx

在这里,我使用 Receive_share_intent 包从其他应用程序接收数据,它在 Android 上运行得很好,但在 IOS 中,当我在 IOS 中共享时,它会打开应用程序,但没有传递任何数据,它也不会触发 StreamSubscriber 包:receive_sharing_intent 这是我有的包一直用来接收数据

在这里,我尝试从 ReceiveSharingIntent 到 _textReceiveIntent(文本)和 _mediaReceiveIntent(媒体文件)获取值,但两者都没有获取任何值,未触发事件的函数将为 null 或 [] 空

_intentDataStreamSubscription =
        ReceiveSharingIntent.getTextStream().listen((String value) {
      _textReceiveIntent(value);
    }, onError: (err) {
      print("getLinkStream error: $err");
    });
    ReceiveSharingIntent.getInitialText().then((String? value) {
      _textReceiveIntent(value);
    });
    // Listen image/video Stream - while app is in foreground
    _intentDataStreamSubscription = ReceiveSharingIntent.getMediaStream()
        .listen((List<SharedMediaFile> value) {
      _mediaReceiveIntent(value);
    }, onError: (err) {
      print("getIntentDataStream error: $err");
    });
    //fetch image/video - while resume from terminate state
    ReceiveSharingIntent.getInitialMedia().then((List<SharedMediaFile> value) {
      _mediaReceiveIntent(value);
    });
Run Code Online (Sandbox Code Playgroud)

这里我期望的是从 ReceiveSharingIntent 接收数据并通过相应的媒介函数传递值

Zak*_*him 0

我只将外部应用程序的 URL 共享到我的 flutter 应用程序,它在我这边工作得很好

解决方案:

将接收共享意图包添加到pubspec.yaml文件中,有一个技巧

重要提示- 要使receive_sharing_intent在 IOS 上发挥作用,只需转储fork并使用版本 {{1.4.5}} (不要使用 ^1.4.5),因为高于 1.4.5 的版本与 android 的 fork 和 Android 不兼容使用下面提到的 fork 进行构建,因为 {{1.4.5}} 与最新的 Gradle、Kotlin 版本不兼容

下面是 Android 的 fork

receive_sharing_intent:
    git:
        url: https://github.com/AyushmanG26/receive_sharing_intent
        ref: master
Run Code Online (Sandbox Code Playgroud)

以下是IOS版本

receive_sharing_intent: 1.4.5
Run Code Online (Sandbox Code Playgroud)

现在我刚刚收到 URL,下面是接收意图的代码

  Future<void> bindShareIntent(BuildContext context) async {
    // For sharing or opening urls/text coming from outside the app while the app is in the memory
    ReceiveSharingIntent.getTextStream().listen((String value) {
      saveUrl(context, value); // value contains the shared URL
    }, onError: (err) { 
      debugPrint("$err");
    });

    // For sharing or opening urls/text coming from outside the app while the app is closed
    ReceiveSharingIntent.getInitialText().then((String? value) {
      saveUrl(context, value); // value contains the shared URL
    });
  }
Run Code Online (Sandbox Code Playgroud)

我希望您已经根据插件的文档为 Android 和 IOS 完成了其他步骤

如果这个解决方案不起作用,我将分享 Android 和 IOS 的完整实现