Skip to main content

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

  1. After unzipping, drag tingyunApp.xcframework into the Xcode project and check 'Copy items if needed'。

  2. Select project TARGETS -> Build Settings -> Search for 'Other Linker Flags' and add the compile flag [-ObjC].

  3. Add dependencies.

Dependency LibraryPurpose
libz.tbdUnzip
WebKit.frameworkBrowser Engine
Security.frameworkAccess Keychain
CoreTelephony.frameworkGet Carrier
SystemConfiguration.frameworkGet Network Status
JavaScriptCore.frameworkSupport Custom JavaScript Error Functionality
CoreGraphics.frameworkSupport Visual Naming Functionality
QuartzCore.frameworkSupport Visual Naming Functionality
CFNetwork.frameworkSupport Mobile Dial Test Functionality
libresolv.tbdSupport Mobile Dial Test Functionality
libc++.tbdc++ Symbolization

SDK Functionality Dependencies (Optional)

Library NameFunctionality
NBSGMKit.frameworkNational encryption for SDK data transmission; NBSGMKit.framework is a dynamic library
TingyunLog.xcframeworkLog retrieval
NBSOOM.xcframeworkOOM crash collection
NBSReplayKit.xcframeworkVideo replay
NBSCPUMonitorKit.xcframeworkCPU monitoring

Add TingYun SDK

  1. 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.

    1. Go to the "Settings" of the application。

      image-20200922143933379

    2. Copy the "App Key" and "host" from"Basic Settings"。

  2. 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>

  1. 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.

  1. Get Scheme.

    • In the app's 'Settings,' select 'Basic Settings,' then choose 'URL Scheme'.

  2. 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]));
    }
    }