iOS SDK Deployment
Get TingYun SDK
CocoaPods Integration
Add the following code to the Podfile in your project::
pod 'tingyunApp'
// Optional features
pod 'NBSGMKit' // SDK data transmission uses national encryption
pod 'TingyunLog' // Log retrieval feature
pod 'NBSOOM' // OOM crash collection feature
pod 'NBSReplayKit' // Video replay feature
pod 'NBSCPUMonitorKit' // CPU monitoring
Saving and execute pod install
。
Manual Integration
-
After unzipping, drag tingyunApp.xcframework into the Xcode project and check 'Copy items if needed'。
-
Select project TARGETS -> Build Settings -> Search for 'Other Linker Flags' and add the compile flag [-ObjC].
-
Add dependencies.
Dependency Library | Purpose |
---|---|
libz.tbd | Unzip |
WebKit.framework | Browser Engine |
Security.framework | Access Keychain |
CoreTelephony.framework | Get Carrier |
SystemConfiguration.framework | Get Network Status |
JavaScriptCore.framework | Support Custom JavaScript Error Functionality |
CoreGraphics.framework | Support Visual Naming Functionality |
QuartzCore.framework | Support Visual Naming Functionality |
CFNetwork.framework | Support Mobile Dial Test Functionality |
libresolv.tbd | Support Mobile Dial Test Functionality |
libc++.tbd | c++ Symbolization |
SDK Functionality Dependencies (Optional)
Library Name | Functionality |
---|---|
NBSGMKit.framework | National encryption for SDK data transmission; NBSGMKit.framework is a dynamic library |
TingyunLog.xcframework | Log retrieval |
NBSOOM.xcframework | OOM crash collection |
NBSReplayKit.xcframework | Video replay |
NBSCPUMonitorKit.xcframework | CPU monitoring |
Add TingYun SDK
-
Get TingYun "host" and "App Key".
Please obtain the App Key and host address from the TingYun platform. Refer to the following steps for details.
-
Go to the "Settings" of the application。
-
Copy the "App Key" and "host" from"Basic Settings"。
-
-
Import the header file.
-
In Objective-C, please import the header file in the project's "pch" file.
#import <tingyunApp/NBSAppAgent.h>
-
In Swift, please import the header file in the project's "Bridging_Header.h" file.
#import <tingyunApp/NBSAppAgent.h>
-
Note: If using the "Log Fetch" feature, you need to import the log library header file: #import <TingyunLog/TingyunLog.h>
-
Introduce the SDK.
-
Objective-C
Initialize the SDK in the "main" method of the "main.m" file in the project.
int main(int argc, char * argv[]) {
@autoreleasepool {
//Enable network module, user experience module, and crash module data collection on first startup. This setting only takes effect on the first startup.
[NBSAppAgent setStartOption:NBSOption_Net|NBSOption_UI|NBSOption_Crash];
//By default, it's HTTPS. If the redirect_host is using the HTTP protocol, then you need to call this interface.
[NBSAppAgent setHttpEnabled:YES];
//The redirect_host is the address of the platform server.
[NBSAppAgent setRedirectURL:@"redirect_host"];
//Your_appkey should be obtained from the platform.
[NBSAppAgent startWithAppID:@"Your_appkey"];
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
} -
Swift
Initialize the SDK in the "application(_:didFinishLaunchingWithOptions:)" method of the "AppDelegate.swift" file.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
NBSAppAgent.setStartOption(Int32(NBSOPTION.NBSOption_Net.rawValue)|Int32(NBSOPTION.NBSOption_UI.rawValue)|Int32(NBSOPTION.NBSOption_Crash.rawValue)) //Enable network module, user experience module, and crash module data collection on first startup. This setting only takes effect on the first startup.
//By default, it's HTTPS. If the redirect_host is using the HTTP protocol, then you need to call this interface.
NBSAppAgent.setHttpEnabled(true)
NBSAppAgent.setRedirectURL("redirect_host")
NBSAppAgent.start(withAppID: "Your_appkey")
return true
}Note: If you need to collect application launch data, please refer toCollect Application Launch。
-
Permission Configuration Instructions
Due to the need for access to the Local Network for the "Mobile Trace Route (MTR)" function, if the "MTR" function is configured, Local Network permissions must be configured in the Info.plist file.
Retrieve User Identity
By adding the "User Identity" specific performance issues for individual users can be retrieved on the TingYun Reporting Platform.
-
Related Interface
/*
Set User Identifier. Cannot exceed 64 characters. Can be called multiple times at any position (value overwrite).
@userId:Unique Identifier for a User
*/
+ (void)setUserIdentifier:(NSString *)userId; -
Code Example
- (void)viewDidLoad
{
[super viewDidLoad];
//The user identifier can be an email address, phone number, or any other information that can identify the user's identity, such as xxx@tingyun.com.
[NBSAppAgent setUserIdentifier:@"userId"];
}
Embed Code Integrity Check
After embedding the code, you can view the output results of the TingYun App SDK logs in the console to determine if the embedding was successful.
- Log Output
NBSAppAgent SDK_Version
NBSAppAgent start!
Success to connect to NBSSERVER
Appendix (Optional Configuration)
Enable Visual Naming
Enabling visual naming allows users to rename 'Native Pages' and 'Actions' through in-app selection, which will be displayed in the User Experience module.
-
Get Scheme.
-
In the app's 'Settings,' select 'Basic Settings,' then choose 'URL Scheme'.
-
-
Add the obtained 'URL Scheme' to TARGETS -> Info -> URL Scheme.
The SDK uses SM encryption for data transmission.
The SDK supports SM encryption for data transmission. Call this interface to enable SM encryption, which is disabled by default. Prerequisite: NBSGMKit.framework must be imported into the project, and the backend needs to be configured to enable SM encryption (please contact technical support to enable backend SM encryption).
Note: This interface needs to be called during SDK initialization.
-
Related Interface
/**
@need If 'yes' is passed, the SDK will use SM encryption for data transmission.
*/
+ (void)encryptionRequired:(BOOL)need; -
Code Example
int main(int argc, char * argv[]) {
@autoreleasepool {
//Enable SM Encryption
[NBSAppAgent encryptionRequired:YES];
//By default, it's HTTPS. If the redirect_host is using the HTTP protocol, then you need to call this interface.
[NBSAppAgent setHttpEnabled:YES];
//The redirect_host is the address of the platform server.
[NBSAppAgent setRedirectURL:@"redirect_host"];
//Your_appkey should be obtained from the platform.
[NBSAppAgent startWithAppID:@"Your_appkey"];
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}