iOS client network detection tool guide

The network detection tool is an SDK plugin from RC. It checks your client’s connection to RC services and provides detailed data reports.

Add it to your test or production app, run checks when needed, and get quality data to quickly find and fix issues.

Network detection process

sequenceDiagram
    App->>NetworkTester: Initialize plugin
    NetworkTester-->>App: Success or failure
    App->>NetworkTester: Register callback listener
    App->>NetworkTester: Start detection
    NetworkTester->>Server: Detecting
    NetworkTester-->>App: Callback returns detecting information
    App->>NetworkTester: (Optional) Actively stop detection
    NetworkTester-->>App: Callback returns final detection result
    NetworkTester->>Server: Report detection result

What you’ll need

  • Get your App Key and its data center
  • Get a Token, like your current client user’s Token

Add the network detection plugin

Use CocoaPods to add the plugin.

  1. Add this to your Podfile:

    # SDK version
    pod 'RongNetworkDetector', '1.0.0'
    
  2. Run this command in the terminal:

    pod install
    

    If you can’t find the version, run pod repo update first, then pod install.

Check network quality

  1. Set up the network detection plugin.

    /// token
    NSString *token = ...
    /// App Key
    NSString *appKey = ...
    /* Area code
    RCDetectorDataCenterBeiJing = 1, //Beijing
    RCDetectorDataCenterSingapore = 2, //Singapore
    RCDetectorDataCenterNorthAmerica = 3 // North America
     */
    RCDetectorDataCenter code = ....
    self.detector = [[RCNetworkDetector alloc] initWithAppKey:appKey
                                                        token:token
                                                     dataCenter:code];
    
    
  2. After setup, add a listener for the results. During detection, the Navi service address, CMP service address, and final result are sent through the RCNetworkDetectorDelegate protocol. Usually, you only need the final result.

     /// Add detection delegate
    [self.detector addDetectorDelegate:self];
     
    /// Remove delegate
    [self.detector removeDetectorDelegate:self];
    
  3. Start detection.

    /// Start detection
    [self.detector start];
    
    

    During detection, these callbacks report results.

    
    /// Network detection started
    /// - Parameters:
    ///   - detector: Detector
    ///   - sessionID: Session ID
    - (void)networkDetector:(RCNetworkDetector *)detector
                  startWith:(NSString *)sessionID;
    
    /// Report Navi detection result
    /// - Parameters:
    ///   - detector: Detector
    ///   - result: Navi detection result
    ///   - index: Navi index
    ///   - count: Total Navi addresses
    ///   - error: Error info
    - (void)networkDetector:(RCNetworkDetector *)detector
           reportNaviResult:(RCNaviConnectResult *)result
                      index:(NSInteger)index
                      count:(NSInteger)count
                      error:(NSError *__nullable)error;
    
    /// Report CMP detection
    /// - Parameters:
    ///   - detector: Detector
    ///   - result: CMP detection result
    ///   - index: CMP index
    ///   - count: Total CMP addresses
    ///   - error: Error info
    - (void)networkDetector:(RCNetworkDetector *)detector
            reportCMPResult:(RCCMPConnectResult *)result
                      index:(NSInteger)index
                      count:(NSInteger)count
                      error:(NSError *__nullable)error;
    
    /// Detection ended
    /// - Parameters:
    ///   - detector: Detector
    ///   - result: Detection type
    ///   - error: Error info
    - (void)networkDetector:(RCNetworkDetector *)detector
               finishedWith:(RCDetectorResult)result
                      error:(NSError *__nullable)error;
    
    
  4. Detection ends automatically after completion.

    You can also stop detection early. After stopping, the plugin will return the final result.

    /// Stop detection
    [self.detector stop];
    
    

Get network detection data

The network detection plugin also provides these query methods:


/// Get Navi results
- (NSArray<RCNaviConnectResult *> *)getNaviResults;

/// Get CMP results
- (NSArray<RCCMPConnectResult *> *)getCMPResults;


/// Get session ID
- (NSString *)getSessionID;

/// Get device info
- (RCNDeviceInfo *)getDeviceInfo;

Reference resources

RCNaviConnectResult

Navigation detection result

@interface RCNaviConnectResult : NSObject
// Navi address
@property(nonatomic, copy) NSString *address;
// Navi version
@property(nonatomic, assign) RCDNaviVersion version;
// Request status
@property(nonatomic, assign) RCDetectorStatus status;
// Total time cost
@property(nonatomic, assign) NSInteger cost;
// TCP time cost
@property(nonatomic, assign) NSInteger connect;
// DNS time cost
@property(nonatomic, assign) NSInteger dns;
// System error code
@property(nonatomic, assign) NSInteger code;
// Remote IP
@property(nonatomic, copy) NSString *remote;
// HTTP status code
@property(nonatomic, assign) NSInteger httpCode;
// System error description
@property(nonatomic, copy) NSString *message;

@end

RCCMPConnectResult

CMP detection result

@interface RCCMPConnectResult : NSObject
// Detection address
@property(nonatomic, copy) NSString *address;
// Detection type: HttpTLS, HttpNoneTLS, WebSocketTLS, WebSocketNoneTLS
@property(nonatomic, copy) RCCMPType type;
// Detection status: Success, failure, timeout
@property(nonatomic, assign) RCDetectorStatus status;
// Detection time cost
@property(nonatomic, assign) NSInteger cost;
// TCP time cost
@property(nonatomic, assign) NSInteger connect;
// DNS time cost
@property(nonatomic, assign) NSInteger dns;
// Business connection time cost
@property(nonatomic, assign) NSInteger bs;
// Business connection result
@property(nonatomic, assign) NSInteger rmtpStatus;
// TCP error code
@property(nonatomic, assign) NSInteger connectCode;
// RMTP error code
@property(nonatomic, assign) NSInteger rmtpCode;
@end

RCNDeviceInfo

Device info

@interface RCNDeviceInfo : NSObject

/// Network type
@property(nonatomic, copy) NSString *networkType;

/// System version
@property(nonatomic, copy) NSString *osVersion;

/// Device model
@property(nonatomic, copy) NSString *deviceModel;

/// Gateway
@property(nonatomic, copy) NSString *gateway;

/// DNS
@property(nonatomic, copy) NSString *dns;

/// Carrier
@property(nonatomic, copy) NSString *carrierName;

/// Proxy
@property(nonatomic, assign) BOOL isProxy;

/// Signal strength (iOS not supported)
@property(nonatomic, assign) NSInteger signal;

@end