Prerequisites
Make sure that the following operations are complete before you initialize Short Video SDK for iOS.
Obtain and activate the license of Short Video SDK for Android. For more information, see Obtain and use a license of Short Video SDK.
Short Video SDK for iOS is integrated. For Short Video SDK V3.29.0 or later, you need to configure the license before you register the SDK. For more information, see Integrate Short Video SDK for Android.
Import the header file
The header file of Short Video SDK defines the specifications that you need to comply with when you use the methods of Short Video SDK. To use Short Video SDK, you must import the header file first.
#import <AliyunVideoSDKPro/AliyunVideoSDKPro.h>Register Short Video SDK for iOS
If you use Short Video SDK 3.29.0 or later, you need to register the SDK after you start the application. Otherwise, Short Video SDK cannot be used. The following code shows how to register Short Video SDK of different versions.
// Register Short Video SDK V3.30.0 or later.
NSError *error = [AliyunVideoSDKInfo registerSDK]; // If nil is returned, the registration is successful.
// In most cases, registration failures result from license integration issues. We recommend that you add an Assert function in your code. This way, if an error occurs during SDK registration, the system returns an error message and provides suggestions on how to fix the error.
NSAssert2(error == nil, @"SDK registration failed. %@;%@", error.localizedDescription, error.localizedRecoverySuggestion);
// Register Short Video SDK 3.29.0.
// Rename the license file to license.crt and add it to your application project. Then, use the following code to obtain the directory in which the license file is stored.
NSString *licenseFilePath = [NSBundle.mainBundle pathForResource:@"license" ofType:@"crt"];
// Register the SDK by using the obtained license key and license file path.
[AliyunVideoSDKInfo registerSDKWithLicenseKey:LicenseKey licenseFile:licenseFilePath];If the license key and license file are successfully imported into the SDK, the registration is successful. However, a successful registration does not indicate that the authentication is successful.
You can use the following code to view the status of the license:
AliyunVideoLicense *license = AliyunVideoLicenseManager.CurrentLicense;When you use a specific feature or value-added service, SDK authentication is required. You can obtain the authentication results from the response to an API operation if authentication fails. You can also listen to the authentication results on a listener.
// Obtain the authentication result for Short Video SDK V3.30.0 or later.
AliyunVideoLicenseManager.EventDelegate = self; // For more information, see the description of AliyunVideoLicenseEventDelegate.View the authentication results:
AliyunVideoLicenseResultCode code = [AliyunVideoLicenseManager check]; If you have updated the license or purchased a value-added service, use the following code to update the license. By default, the system updates the license every 15 minutes.
[AliyunVideoLicenseManager Refresh:^(AliyunVideoLicenseRefreshCode code){
// The information about the license verification result.
}];Specify the resource package path
If you integrate Short Video SDK by using the least dependency integration method but you want to add the AliyunVideoSDKPro.bundle resource package, you can perform the following steps to automatically download the resource package when you run the application. The resource package is added to Short Video SDK after the download is complete.
Upload the resource package to the cloud. For example, you can upload the resource package to an Object Storage Service (OSS) bucket.
Check whether the resource package exists when the application is started. If the resource package does not exist, the system downloads the resource package to your local device. If the resource package already exists, proceed to the next step.
Specify the path in which the resource package is stored. Sample code:
[AliyunVideoSDKInfo setSDKBundlePath:@"The path in which the resource bundle is stored on the local device"];
Log output
By default, Short Video SDK generates alert and error logs at the AlivcLogWarn level. You can set the log level to generate more levels of logs for troubleshooting.
// The following levels of logs are supported:
typedef NS_ENUM(NSInteger, AlivcLogLevel)
{
AlivcLogClose = 1,
AlivcLogVerbose,
AlivcLogDebug,
AlivcLogInfo,
AlivcLogWarn,
AlivcLogError,
AlivcLogFatal
};
// Specify the level of the logs to be generated.
[AliyunVideoSDKInfo setLogLevel:AlivcLogDebug];
Query the version information
You can use the following code to display the version information of Short Video SDK. This helps you verify the version of the integrated SDK and troubleshoot issues that may occur when you use the SDK.
[AliyunVideoSDKInfo printSDKInfo];You can also print the information as needed.
NSString *version = [AliyunVideoSDKInfo version]; // The version number.
NSString *module = [AliyunVideoSDKInfo module]; // The version type.
int moduleCode =[AliyunVideoSDKInfo versionCode]; // Display the code of the version type.
NSString *buildId =[AliyunVideoSDKInfo videoSDKBuildId]; // Display the build ID of the SDK version.
NSLog(@"\n==============\nVERSION: %@\nBUILD_ID: %@\nMODULE: %@\nMODULE_CODE: %d\n==============", version, buildId, module, moduleCode);