All Products
Search
Document Center

Apsara Video SDK:Update of Push SDK for iOS

Last Updated:Mar 22, 2024

This topic describes how to update Push SDK for iOS from V4.0.2 to V4.1.0 or later.

Prerequisites

The latest version of Push SDK for iOS is downloaded.

For more information, see Download SDKs.

Procedure

Remove the related class libraries and resource files of SDK V4.0.2 from the project. Add the related class libraries and resource files of SDK V4.1.0 or later. Check and modify the related key methods and methods in the main process of stream ingest.

  1. In the libs directory of the project, replace the AliLivesdk.framework file with the AlivcLivePusher.framework and AlivcLibRtmp.framework files in the SDK package of V4.1.0 or later.

  2. Update ApsaraVideo Player SDKs to AliyunPlayer SDKs. For more information, see Push SDK for iOS and ApsaraVideo Player SDKs used in the demo directory of Push SDK for iOS.

  3. If you want to integrate Queen SDK for iOS, view the usage notes in the demo directory of Push SDK for iOS to facilitate the integration of Queen SDK for iOS and UI.

  4. Changes are made to some key methods. View the "Comparison of key methods" section of this topic to check and modify the related methods in your code.

  5. Changes are made to some methods in the main process of stream ingest. View the "Changes in methods in the main process of stream ingest" section of this topic to check and modify your code.

Comparison of key methods

  • Basic methods

    V4.0.2

    V4.1.0 and later

    Description

    getSdkVersion

    getSdkVersion

    Queries the version number of Push SDK for iOS.

    initWithConfig

    initWithConfig

    Creates a stream ingest object.

    destorySdk

    destroy

    Destroys a stream ingest object.

    • setStatusDelegate

    • setRtsDelegate

    • setVidePreProcessDelegate

    • setDataStatsDelegate

    • AlivcPublisherViewDelegate

    • AlivcLivePusherInfoDelegate

    • AlivcLivePusherErrorDelegate

    Sets the callback for the audio and video streams of a fan during stream ingest over Real-Time Communication (RTC). To set video preprocessing callbacks, use the AliLiveRtsDelegate class. Sets the callback for parameters that are related to live streaming media.

    setNetworkDelegate

    AlivcLivePusherNetworkDelegate

    Sets the callback for the network status during stream ingest.

    setLogDirPath

    N/A: Custom logs are written.

    Sets the path for storing the log files of Push SDK for iOS. To prevent log loss, you must call this method before other methods. In addition, make sure that the specified path exists and is writable.

    setLogLevel

    N/A

    Sets the log level.

  • Basic stream ingest methods

    V4.0.2

    V4.1.0 and later

    Description

    startPreview

    startPreview

    Starts the preview. This method is called on the streamer side.

    stopPreview

    stopPreview

    Stops the preview. This method is called on the streamer side.

    pausePush

    pause

    Stops the camera from collecting live streams and ingests standby streams. This method is supported only for stream ingest over Real-Time Messaging Protocol (RTMP). You must call the startPush() method before the pausePush() method.

    resumePush

    resume()

    Enables the camera to collect live streams again and stops ingesting standby streams. This method is supported only for stream ingest over RTMP. You must call the pausePush method before the resumePush method.

    startPush

    startPushWithURL

    Starts the stream ingest.

    stopPush

    stopPush

    Stops the stream ingest.

    isPublishing

    isPushing

    Queries whether streams are being ingested.

    getPublishUrl

    getPushURL

    Queries the current ingest URL.

  • Video-related methods

    V4.0.2

    V4.1.0 and later

    Description

    setPreviewMode

    setpreviewDisplayMode

    Sets the preview mode.

    switchCamera

    switchCamera

    Switches between the front and rear cameras.

    setCameraZoom

    setZoom

    Sets the zoom factor of the camera and specifies whether to enable the flash.

    isCameraExposurePointSupported

    setExposure

    Queries whether an exposure point can be set for the camera.

    setCameraFocusPoint

    setAutoFocus

    Sets the focus point of the camera.

  • Audio-related methods

    V4.0.2

    V4.1.0 and later

    Description

    setMute

    setMute

    Specifies whether the frames collected from the local audio are mute frames.

    isAudioOnly

    isAudioOnly

    Queries whether the ingested streams are audio-only streams.

    enableEarBack

    setBGMEarsBack

    Enables in-ear monitoring. To prevent echoes, we recommend that you enable in-ear monitoring after you insert the headset.

    playBGM

    startBGMAsync

    Starts the playback of background music.

    stopBGM

    stopBGM

    Stops the playback of background music.

    pauseBGM

    pauseBGM

    Pauses the playback of background music.

    resumeBGM

    resumeBGM

    Resumes the playback of background music.

    setBGMVolume

    setBGMVolume

    Sets the volume of background music.

Changes in methods in the main process of stream ingest

  1. Create an engine.

    V4.0.2: AliLiveEngine

    V4.1.0 and later: AlivcLivePusher

    // Create an AliLiveRTMPConfig object.
    Import a header file. #import <AliLiveSdk/AliLiveSdk.h>
    Create an AliLiveEngine object. AliLiveConfig *config = [[AliLiveConfig alloc] init];
    config.videoProfile = AliLiveVideoProfile_540P;
    config.videoFPS = 20;
    myConfig.pauseImage = [UIImage imageNamed:@"background_img.png"];
    myConfig.accountID = @"";
    AliLiveEngine *engine = [[AliLiveEngine alloc] initWithConfig:myConfig];
    [engine setAudioSessionOperationRestriction:AliLiveAudioSessionOperationRestrictionDeactivateSession];
    [engine setRtsDelegate:self];
    [engine setStatusDelegate:self];

    Import the header file in the view controller that requires AlivcLivePusher by using the following statement: #import <AlivcLivePusher/AlivcLivePusherHeader.h>. The following sample code provides an example:

    // Initialize the stream ingest configurations. You can also use the initWithResolution method to initialize the stream ingest configurations.
    AlivcLivePushConfig *config = [[AlivcLivePushConfig alloc] init];
    // The default resolution is 540p. The supported maximum resolution is 720p.
    config.resolution = AlivcLivePushResolution540P;
    // We recommend that you set the frame rate to 20 frames per second (FPS).
    config.fps = AlivcLivePushFPS20;
    // Specify whether to enable adaptive bitrate streaming. Default value: true.
    config.enableAutoBitrate = true;
    // The default keyframe interval is 2. Higher keyframe intervals cause higher latency. We recommend that you set the keyframe interval to a number from 1 to 2.
    config.videoEncodeGop = AlivcLivePushVideoEncodeGOP_2;
    // The unit of the reconnection interval is millisecond. The default reconnection interval is 2 seconds. The reconnection interval must be at least 1 second. We recommend that you use the default value.
    config.connectRetryInterval = 2000;
    // The default value of the previewMirror parameter is false. We recommend that you use the default value.
    config.previewMirror = false;
    // By default, the preview is in portrait mode. You can change the mode to landscape left or landscape right.
    config.orientation = AlivcLivePushOrientationPortrait;
  2. Create a preview.

    V4.0.2

    V4.1.0 and later

    // Start the preview. [self.engine startPreview:self.renderView];

    The following preview modes are supported:

    You can specify these modes by using the AlivcLivePushConfig class. You can also call the setpreviewDisplayMode method to specify a preview mode during preview and stream ingest.

    [self.livePusher startPreview:self.view];
  3. Start the stream ingest.

    V4.0.2

    V4.1.0 and later

    [self.engine startPushWithURL:self.pushUrl];
    [self.livePusher startPushWithURL:@"Ingest URL for testing (rtmp://......)"];
  4. Stop the stream ingest.

    V4.0.2

    V4.1.0 and later

    [self.engine stopPush];
    [self.engine stopPreview];
    [self.engine destorySdk];
    self.engine = nil;
    [self.livePusher destory];
    self.livePusher = nil;
    /* Query the status of stream ingest. */
    AlivcLivePushStatus status = [self.livePusher getLiveStatus];