All Products
Document Center

Mobile Platform as a Service:Use SDK

Last Updated:Jan 15, 2021

Perform the following steps to diagnose the iOS client problems:

  1. Initialize diagnosis service
  2. Set user ID
  3. Write diagnosis logs
  4. View local diagnosis logs
  5. Obtain online user diagnosis logs

Initialize diagnosis service

Before using the diagnosis function, initialize it first.

  1. #import <MPDiagnosis/MPDiagnoseAdapter.h>
  2. [MPDiagnoseAdapter initDiagnose];

The diagnosis service supports pulling logs through Sync or Push method. Codes for initializing the diagnosis service vary with the log pulling method.

Use Mobile Sync Service (Sync)

If you use the Sync method to pull diagnostic logs, you need to initialize the service before using the diagnostic function.

  1. #import <MPDiagnosis/MPDiagnoseAdapter.h>
  2. [MPDiagnoseAdapter initDiagnose];

Use Message Push Service (Push)

You need to integrate the Message Push Service, and complete Message Push Service initialization first. After receiving the message pushed, call the following method:

  1. #import <APLog/APLogMgr.h>
  2. [[APLogMgr sharedInstance] handlePushDiagnosisCmd:[notification.userInfo objectForKey:@"content"]];

Upgrade precautions

The Category file of the APLogUser class does not need to be added since version 10.1.32. The middle tier implements packaging. After upgrade, check for configurations of the earlier version in the project and delete them if any. The following shows the configurations that must be removed from the new version.


Set user ID

The diagnosis service extracts logs based on user ID.

  1. Set user ID by using the userId function during the implementation of MPaaSInterface.


  2. During user switching, that is, when the value configured in the userId function of MPaaSInterface changes, call the following function:
    1. [MPDiagnoseAdapter userChange];
    For more information, see the MPDiagnoseAdapter.h file under MPDiagnosis.

Write diagnosis logs

Call the following method to write diagnosis logs on the critical link of the App:

  1. /**
  2. * Log a message with kAPLogLevelInfo level.
  3. *
  4. * @param message An NSString object that contains a printf-style string containing a log message and placeholders for the arguments.
  5. * @param ... The arguments displayed in the format string.
  6. */
  7. #define APLogInfo(tag,fmt, ...) \
  8. APLogToFile(tag, kAPLogLevelInfo, fmt, ##__VA_ARGS__)

For more information, see the APLog.h file under APLog.

For example, call the following statement to write diagnosis logs after startup:

  1. APLogInfo(@"mPaaS", @"Start Cost %d", time);
  • Logs written by APLogInfo are not printed in the Xcode console. To print related logs in the console during the development phase, add the ConsoleLog file to the project.
  • Out of security concerns, if you do not want your App to print any logs (including logs printed by NSLog and APLogInfo) after going online, you can add the RemoveNSLog file to the project when the app’s release package is generated.

View local diagnosis logs

You can find diagnosis logs in the sandbox directory, as shown in the following figure. This type of logs are not reported by default. The console delivers a command to extract the logs when required.


Note: The diagnosis logs saved locally on the client are limited by the retention period and file size. The diagnosis SDK on the client follows the following policies when the App runs in the backend or when the process is ended:
  • Retention period: 6 days by default. If the SDK detects that the file of logs of the previous 3 days exceeds 30 MB, the logs of the previous 3 days are all deleted.
  • File size: not more than 100 MB by default When the file size exceeds 100 MB, earlier logs of a half size are deleted. For example, if the file size is 120 MB, 60 MB logs are deleted.

Obtain online user diagnosis logs

After your App is released and goes online, if you need to obtain the local diagnosis logs on the client for troubleshooting, you can deliver a command in the mPaaS console to obtain related diagnosis logs. For detailed operations, see Mobile Analysis > Extract logs.