Skip to content

iOS app crash when _nativePlugin.createPipContentView() #13

@Sahilpervez

Description

@Sahilpervez

[iOS Crash] App crashes when calling _setupPip() using pip: ^0.0.3 with agora_rtc

Description

I am implementing Picture-in-Picture (PiP) mode for the video call feature in my Flutter app.

  • Using agora_rtc for the video call functionality.
  • Using pip: ^0.0.3 to implement PiP.
  • Everything works perfectly on Android.
  • On iOS, the app crashes as soon as the line _pipContentView = await _nativePlugin.createPipContentView(); is executed.

How I'm using it

I found _setupPip() method in example section of the pip plugin. I call the _setupPip() function inside the initState() of the video call screen to enable PiP before the video call starts.

Function that causes the crash

Future<void> _setupPip() async {
  if (Platform.isIOS && _pipContentView == 0) {
    _pipContentView = await _nativePlugin.createPipContentView(); // crash happens here
    print('[createPipContentView]: $_pipContentView');
    _pipContentView = _pipContentView;
    if (mounted) {
      setState(() {});
    }
  }

  final options = PipOptions(
    autoEnterEnabled: _autoEnterEnabled,
    aspectRatioX: aspectRatioX.toInt(),
    aspectRatioY: aspectRatioY.toInt(),
    sourceRectHintLeft: 0,
    sourceRectHintTop: 0,
    sourceRectHintRight: 0,
    sourceRectHintBottom: 0,
    seamlessResizeEnabled: true,
    useExternalStateMonitor: true,
    externalStateMonitorInterval: 100,
    contentView: _pipContentView,
    sourceContentView: _playerView,
    preferredContentWidth: 200,
    preferredContentHeight: 200,
    controlStyle: 2,
  );

  try {
    final success = await _pip.setup(options);
    print('PiP Setup ${success ? 'successful' : 'failed'}');
  } catch (e) {
    print('PiP Setup error: $e');
  }
}

I have changed the version of sdk in native_plugin from (^3.7.0 to 3.6.2) to match the version of sdk that is used in my project.

environment:
  sdk: ^3.6.2
  flutter: '>=3.3.0'

flutter doctor log :

fvm flutter doctor

Doctor summary (to see all details, run flutter doctor -v):

[✔] Flutter (Channel stable, 3.27.4, on mac05 15.5 24F74 darwin-x64, locale en-IN)

[✔] Android toolchain - develop for Android devices (Android SDK version 35.0.0)

[✔] Xcode - develop for 105 and macOS (Xcode 16.4)

[✔] Chrome-develop for the web

[✔] Android Studio (version 2024.1)

[✔] VS Code (version 1.89.1)

[✔] Connected device (2 available)

[✔] Network resources

Please let me know If I need to do some extra setup in my_project/ios folder to get the things to work smoothly on iOS.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions