Prerequisites
Complete the following steps before you initialize the SDK:
-
Obtain and activate a license for the short video SDK. For more information, see Obtain a license for the short video SDK.
-
Integrate the short video SDK. Starting from version 3.29.0, you must configure the license before you register the SDK. For more information, see Integrate the SDK.
Import header files
Import the SDK header files before you use the short video SDK. The header files contain the API declarations required by the SDK.
-
Version 7.0.0
Starting from version 7.0.0, the import method is unified.
#import <AliVCSDK_ShortVideo/AliVCSDK_ShortVideo.h> -
Before version 7.0.0
-
Professional Edition & Standard Edition
#import <AliyunVideoSDKPro/AliyunVideoSDKPro.h> -
Basic Edition
#import <AliyunVideoSDKBasic/AliyunVideoSDKBasic.h>
-
Register the SDK
Starting from version 3.29.0, the short video SDK uses an upgraded license service. Register the SDK after your app starts to enable the SDK features. The following code shows how to register the SDK:
// For versions 3.30.0 and later:
NSError *error = [AliyunVideoSDKInfo registerSDK]; // If the returned error is nil, the registration is successful.
// A registration failure is usually caused by an integration error. Add an Assert statement to display the error and suggested fix during integration and debugging.
NSAssert2(error == nil, @"Failed to register the SDK! %@; %@", error.localizedDescription, error.localizedRecoverySuggestion);
// For version 3.29.0:
// Rename the obtained LicenseFile to license.crt. Add the file to your app project. Then, use the following method to get the path of the LicenseFile.
NSString *licenseFilePath = [NSBundle.mainBundle pathForResource:@"license" ofType:@"crt"];
// Use the obtained LicenseKey and LicenseFilePath to register the SDK.
[AliyunVideoSDKInfo registerSDKWithLicenseKey:LicenseKey licenseFile:licenseFilePath];
A successful registration means the license is loaded into the SDK, but does not confirm that authentication was successful.
Query the current license status with the following code.
AliyunVideoLicense *license = AliyunVideoLicenseManager.CurrentLicense;
The SDK authenticates when you use specific features or value-added services. If authentication fails, the corresponding API call returns a failure result. You can also listen for authentication results from a central location.
// For versions 3.30.0 and later
AliyunVideoLicenseManager.EventDelegate = self; // For more information, see the AliyunVideoLicenseEventDelegate protocol description.
Proactively query the authentication result with the following code.
AliyunVideoLicenseResultCode code = [AliyunVideoLicenseManager check];
If you renew your subscription or purchase a value-added service, you can manually update the license. By default, the SDK checks for updates every 15 minutes.
[AliyunVideoLicenseManager Refresh:^(AliyunVideoLicenseRefreshCode code){
// Update result: code
}];
Set the resource bundle import path
If you integrate the short video SDK by using CocoaPods with minimum dependencies, you may need to import the AliyunVideoSDKPro.bundle resource bundle. To reduce your app's package size, configure the app to download the resource bundle at runtime. After the download completes, set the bundle path to make it available to the SDK.
-
Upload the resource bundle to your cloud storage, such as Object Storage Service (OSS).
-
When the app starts, check for the resource bundle. If the bundle does not exist, download it to your local device.
-
After the resource bundle is downloaded or if it already exists locally, set the import path for the resource bundle in the short video SDK as follows:
[AliyunVideoSDKInfo setSDKBundlePath:@"The local storage path of the resource bundle"];
Log output
By default, the short video SDK outputs only warning and error logs (AlivcLogWarn). Set the log level to print more detailed logs for troubleshooting.
// The log levels are defined as follows:
typedef NS_ENUM(NSInteger, AlivcLogLevel)
{
AlivcLogClose = 1,
AlivcLogVerbose,
AlivcLogDebug,
AlivcLogInfo,
AlivcLogWarn,
AlivcLogError,
AlivcLogFatal
};
// Set the log output level
[AliyunVideoSDKInfo setLogLevel:AlivcLogDebug];
Version information
Print the version information to confirm the correct SDK version is imported or to help with troubleshooting:
[AliyunVideoSDKInfo printSDKInfo];
You can also print specific fields:
NSString *version = [AliyunVideoSDKInfo version]; // Version number
NSString *module = [AliyunVideoSDKInfo module]; // Version type
int moduleCode =[AliyunVideoSDKInfo versionCode]; // Version type code
NSString *buildId =[AliyunVideoSDKInfo videoSDKBuildId]; // Version packaging ID
NSLog(@"\n==============\nVERSION: %@\nBUILD_ID: %@\nMODULE: %@\nMODULE_CODE: %d\n==============", version, buildId, module, moduleCode);