This topic describes how to update Push SDK for iOS from V4.0.2 to V4.1.0 or later.
For information about the new versions of Push SDK, see Overview.
Remove the class libraries and resource files of Push SDK V4.0.2 from your project. Then, add the class libraries and resource files of Push SDK V4.1.0 or later to your project.
- In the libs directory, use AlivcLivePusher.framework and AlivcLibRtmp.framework of Push SDK V4.1.0 or later to replace AliLivesdk.framework of Push SDK V4.0.2.
- Update the ApsaraVideo Player SDK to AliyunPlayer. For more information, see SDK and the SDK used in the demo.
- If you want to implement the smart retouching feature in your app, view the usage instructions in the demo. This facilitates the integration of the Queen SDK and UI.
- Modify specific methods, as described in the Key methods section of this topic.
- Modify specific methods for the major process, as described in the Changes in the methods for major process section of this topic.
- Basic methods
V4.0.2 V4.1.0 and later Description getSdkVersion getSdkVersion Queries the version of Push SDK. initWithConfig initWithConfig Creates a stream ingest object. destorySdk destory Destroys the stream ingest object.
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. 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 RTMP. You must call the startPush method before the pausePush method to prevent an invalid call order. 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 to prevent an invalid call order. startPush startPushWithURL Starts to ingest streams. stopPush stopPush Stops ingesting streams. 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 the 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 Plays background music. stopBGM stopBGM Stops playing 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 the methods for major process
- Create an engine.
AliLiveEngine in V4.0.2 AlivcLivePusher in V4.1.0 and later
// Create an AliLiveConfig 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];
Run the following command to import the header file for the view controller that requires the streamer:
#import <AlivcLivePusher/AlivcLivePusherHeader.h>. The following code provides an example:
// Initialize the stream ingest configurations. You can also use initWithResolution to realize the same purpose. 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; // Enable adaptive bitrate streaming. The default value is 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 milliseconds. 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;
- 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:
- ALIVC_LIVE_PUSHER_PREVIEW_SCALE_FILL: In this mode, the video fills the entire preview view. If the aspect ratio of the video does not match the view, the preview image is deformed.
- ALIVC_LIVE_PUSHER_PREVIEW_ASPECT_FIT: In this mode, the initial aspect ratio of the video is used during the preview. If the aspect ratio of the video does not match the view, black edges appear on the preview view, which is set by default.
- ALIVC_LIVE_PUSHER_PREVIEW_ASPECT_FILL: In this mode, the aspect ratio of the video is changed to fit the preview view. If the aspect ratio of the video does not match the view, the video is cropped to fit the preview view.
You can specify these modes in AlivcLivePushConfig. You can also call the setpreviewDisplayMode method to specify a preview mode during preview and stream ingest.
- Start to ingest streams.
V4.0.2 V4.1.0 and later
[self.livePusher startPushWithURL:@"Ingest URL for test (rtmp://......)"];
- Stop ingesting streams.
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; /* Obtain the status of stream ingest. */ AlivcLivePushStatus status = [self.livePusher getLiveStatus];