logo
On this page

FAQs


iOS

  1. Open the project with Xcode, and click the+ Capability on the Signing & Capabilities page.

    And double-click on Background Modes in the pop-up window. This will allow you to see the Background Modes configuration in the Signing & Capabilities.

  2. Check the Audio, AirPlay, and Picture in Picture option in the Background Modes configuration.

Android

In Android, when an app goes to the background or the screen is locked, the application service may be reclaimed by the system, causing interruptions in camera and microphone access. However, you can implement a Foreground Service to keep the app alive in the background. For detailed implementation, you can refer to Foreground Service.

Live Streaming Kit (ZegoUIKitPrebuiltLiveStreaming) allows to forcefully end a livestream room and dismiss all audience automatically when the host ends the livestream. To implement this, use the onEnded callback. This callback will be triggered when the host ends the livestream, and all audience will automatically exit the livestream room.

Here is the reference code:

class LivePage extends StatelessWidget {
  const LivePage({
    Key? key,
    required this.liveID,
    this.isHost = false,
  }) : super(key: key);

  final String liveID;
  final bool isHost;

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: ZegoUIKitPrebuiltLiveStreaming(
        appID: YourSecret.appID,
        appSign: YourSecret.appSign,
        userID: 'userID',
        userName: 'userName',
        liveID: liveID,
        events: ZegoUIKitPrebuiltLiveStreamingEvents(
          onEnded: (
            ZegoLiveStreamingEndEvent event,
            VoidCallback defaultAction,
          ) {
            if (ZegoLiveStreamingEndReason.hostEnd == event.reason) {
              if (event.isFromMinimizing) {
                ZegoUIKitPrebuiltLiveStreamingController().minimize.hide();
              } else {
                Navigator.pop(context);
              }
            } else {
              defaultAction.call();
            }
          },
        ),
        // Modify your custom configurations here.
        config: isHost
            ? ZegoUIKitPrebuiltLiveStreamingConfig.host()
            : ZegoUIKitPrebuiltLiveStreamingConfig.audience(),
      ),
    );
  }
}

If you are on the audience side and want to know about the host's changes, such as when the host enters or leaves the live streaming room, you can listen to ZegoUIKitPrebuiltLiveStreamingController.connect.hostNotifier.

This is a ValueNotifier<ZegoUIKitUser?> object that provides real-time notifications when the host changes.

Here is the reference code:

class LivePage extends StatefulWidget {
  final String liveID;
  final bool isHost;

  const LivePage({
    Key? key,
    required this.liveID,
    this.isHost = false,
  }) : super(key: key);

  @override
  State<StatefulWidget> createState() => LivePageState();
}

class LivePageState extends State<LivePage> {
  @override
  void initState() {
    super.initState();

    ZegoUIKitPrebuiltLiveStreamingController()
        .coHost
        .hostNotifier
        .addListener(onHostUpdated);
  }

  @override
  void dispose() {
    super.dispose();

    ZegoUIKitPrebuiltLiveStreamingController()
        .coHost
        .hostNotifier
        .removeListener(onHostUpdated);
  }

  void onHostUpdated() {
    debugPrint(
        'host update:${ZegoUIKitPrebuiltLiveStreamingController().coHost.hostNotifier.value}');
  }

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: ZegoUIKitPrebuiltLiveStreaming(
        appID: YourSecret.appID,
        appSign: YourSecret.appSign,
        userID: 'userID',
        userName: 'userName',
        liveID: widget.liveID,
        config: (widget.isHost
            ? ZegoUIKitPrebuiltLiveStreamingConfig.host()
            : ZegoUIKitPrebuiltLiveStreamingConfig.audience()),
      ),
    );
  }
}

In Android, when running in debug mode, the application works fine. However, in release mode, it crashes due to code obfuscation.

To prevent obfuscation of the SDK public class names, do the following:

1

In your project's 'your_project > android > app' folder, create a 'proguard-rules.pro' file with the following content as shown below

-keep class **.zego.** { *; }
2

Add the following config code to the 'release' part of the 'your_project/android/app/build.gradle' file

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

Enable UIKit Logging

You can refer to the following code to enable logging in UIKit:

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  final navigatorKey = GlobalKey<NavigatorState>();

  ZegoUIKit().initLog().then((value) {
    runApp(MyApp(
      navigatorKey: navigatorKey,
    ));
  });
}

Retrieve the UIKit logs

Android

The UIKit logs on Android can be found in the following directory: /sdcard/Android/data/[YOUR_APP_PACKAGE]/files/ZegoPrebuilt/Logs/.

iOS

  1. Export Container

    a. Open Xcode and select Window -> Devices and Simulators.

    b. Container Select the device and the app, then download the corresponding container.

  2. The UIKit logs on iOS can be found in the following directory within the container:

    [YOUR_APP_CONTAINER]/AppData/Library/Application Support/Logs

class LivePage extends StatelessWidget {
  const LivePage({Key? key, required this.liveID, this.isHost = false})
      : super(key: key);

  final String liveID;
  final bool isHost;

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: ZegoUIKitPrebuiltLiveStreaming(
        appID: YourSecret.appID,
        appSign: YourSecret.appSign,
        userID: localUserID,
        userName: 'user_$localUserID',
        liveID: liveID,

        // Modify your custom configurations here.
        config: (isHost
          ? ZegoUIKitPrebuiltLiveStreamingConfig.host()
          : ZegoUIKitPrebuiltLiveStreamingConfig.audience())
// !mark
          ..audienceAudioVideoResourceMode = ZegoAudioVideoResourceMode.onlyL3,
      ),
    );
  }
}

Previous

Customize the layout

Next

API

On this page

Back to top