Prerequisites
Environment requirements
iOS >= 9.0
Xcode >= 10.0
Component dependency
tars
MQQComponents
TMFShark
SSZipArchive
PromiseObjC
MJRefresh
SocketRocket
Brotli
CocoaAsyncSocket
Integration method
TCMPPSDK can be integrated in the following ways:
CocoaPods integration
Manual integration
SPM integration
CocoaPods integration
1. Add the source and mini program dependency modules to the Podfile in your project:
# Pods repository
source 'https://e.coding.net/tcmpp-work/tcmpp/tcmpp-repo.git'
target 'YourTarget' do
# ――― TCSAS -----―――――――――――――――――――――――――――――――――――――――――――――――――――――--- #
pod 'TCMPPSDK'
pod 'TCMPPExtScanCode'
pod 'TCMPPExtMedia'
# Preset base library
pod 'TCSASBaseLib'
end
In this case, Replace YourTarget with the name of the target in your project that requires the SDK.
2. Run cd on the Terminal to go to the Podfile directory and run pod install to install the component.
Manual integration
1. Add the SDK
Add the directory of the SDK components to the appropriate location in your Xcode project and select the relevant target.
You can quickly add the components by dragging the directory directly from Finder into your Xcode project.
2. Add dependent SDKs
Add all components depended on by SDK to the project. For the list of dependent components, see Component dependency. 3. Add dependent system libraries
Add the system libraries that the SDK depends on to the project, open the project settings page in Xcode, select the target, and click General to add them under Linked Frameworks and Libraries.
4. The system library dependencies are as follows:
Foundation.framework
CoreTelephony.framework
CFNetwork.framework
Security.framework
SystemConfiguration.framework
CoreService.framework
CoreFoundation.framework
libz.tbd
libc++.tbd
libc.tbd
libbz2.tbd
libsqlite3.0.tbd
5. Project settings
After adding the SDK, you need to make the following project settings in Xcode:
Select Build Settings > Linking > Other Linker Flags, and add -ObjC.
Select Build Settings > Apple Clang - Custom Compiler Flags > Other C Flags, and add
-fshort-wchar
-D__FIXWCHART__
Select Build Phases > Copy Bundle Resources, and add the SDK resource file:
SPM integration
Select the version rule (Up to Next Major Version is recommended) and click Add Package.
After adding the SDK, make the following project settings in Xcode:
Select Build Settings > Linking > Other Linker Flags, and add -ObjC.
Obtain the configuration file
The initialization of the mini program SDK relies on the configuration file obtained from the SAS (Super App as a Service) console. Before integrating the mini program SDK, you need to get this configuration file.
Log in to the console, and click Create superapp.
Fill in the superapp information.
Add Bundle ID.
Download the configuration file.
Note:
The default name of the downloaded configuration file is tcsas-ios-configurations.json.
Add the configuration file to the project
After obtaining the configuration file, add it to your superapp’s source code.
Note:
The bundleId of the iOS project must match the bundleId configured in the console. If they do not match, the mini program SDK will lead to initialization errors.
Add permission settings
If you have only integrated the core library of the SDK, namely TCMPPSDK, you need to add permission request information in the info.plist file.
The permissions involved with the core SDK (TCMPPSDK) are as follows:
|
Photo library write | NSPhotoLibraryAddUsageDescription | saveImageToPhotosAlbum, saveVideoToPhotosAlbum |
Camera | NSCameraUsageDescription | CameraContext (Camera component) |
Microphone | NSMicrophoneUsageDescription | CameraContext (Camera component) |
If you need to use the extension SDK, you must also add the corresponding permission request information in the project's info.plist file.
Configure to support landscape mode
The loading page in the SDK, video components, etc., support landscape mode, but the superapp project must also support it.
Please check the following options in Xcode settings:
Note:
If landscape mode is not enabled, the landscape features in the SDK will not work.
Import the header file
Import the header file into AppDelegate.
#import <TCMPPSDK/TCMPPSDK.h>
Set the configuration information
Initialize the TMAServerConfig object based on the configuration file, and use it to initialize the mini program engine.
The SDK supports direct engine initialization, preparing network connections in advance, and updating base library and configuration information to speed up mini program loading. It can also support initialization when needed.
Example:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"tcsas-ios-configurations" ofType:@"json"];
if(filePath) {
TMAServerConfig *config = [[TMAServerConfig alloc] initWithFile:filePath];
[[TMFMiniAppSDKManager sharedInstance] setConfiguration:config];
}
Other initialization operations
You can set up the implementation instance of the open API as needed. If integrating extension modules, prepare the initialization of the extension API.
[TMFMiniAppSDKManager sharedInstance].miniAppSdkDelegate = [MIniAppDemoSDKDelegateImpl sharedInstance];
MIniAppDemoSDKDelegateImpl must implement the TMFMiniAppSDKDelegate protocol. See Introduction and the MIniAppDemoSDKDelegateImpl file in the Demo project. Open a mini program
You can directly call the API to open the mini program using the appid:
[[TMFMiniAppSDKManager sharedInstance] startUpMiniAppWithAppID:appId parentVC:self completion:^(NSError * _Nullable error) {
NSLog(@"open applet error:%@",error);
}];