Other React Native APIs

Important

Visual Studio App Center is scheduled for retirement on March 31, 2025. While you can continue to use Visual Studio App Center until it is fully retired, there are several recommended alternatives that you may consider migrating to.

Learn more about support timelines and alternatives.

Adjust the log level

You can control the amount of log messages that show up from App Center. Log messages show in the console on iOS and LogCat on Android. Use the setLogLevel API to enable additional logging while debugging. The default level is LogLevel.ASSERT for the iOS App Store environment and Android release builds. Otherwise, it's set to LogLevel.WARNING.

To output all log messages, use LogLevel.VERBOSE.

import AppCenter from 'appcenter';

await AppCenter.setLogLevel(AppCenter.LogLevel.VERBOSE);

Note

The JavaScript setLogLevel API can't increase logging for app startup code, before JavaScript is loaded.

If you wish to increase logging for app startup, use the native App Center setLogLevel APIs.

In iOS, call [MSACAppCenter setLogLevel: MSACLogLevelVerbose]; before any call to [AppCenterReactNative register]; (or AppCenterReactNativeAnalytics or AppCenterReactNativeCrashes or AppCenterReactNativePush) in the project's AppDelegate.m. You must add @import AppCenter; if missing in that file.

In Android, call AppCenter.setLogLevel(android.util.Log.VERBOSE); before SoLoader.init in onCreate callback in MainApplication.java.

Identify installations

The App Center SDK creates a UUID for each device once the app is installed. This identifier remains the same for a device when the app is updated and a new one is generated only when the app is re-installed or the user manually deletes all app data on Android. The following API is useful for debugging purposes.

import AppCenter from 'appcenter';

const installId = await AppCenter.getInstallId();   // Returned as a string

Identify users

The App Center SDK supports setting a user ID that's used to augment crash reports. To use this capability:

  1. Configure the App Center SDK as described in the App Center SDK Getting started guide.
  2. Set a userID in the SDK using the following code:
AppCenter.setUserId("your-user-id");

After setting a user ID, you can use App Center's search feature to search for specific crash reports for the ID. Learn more in App Center's search documentation.

Note

The value for the user ID is limited to 256 characters. It will be shown with your crash reports but not used for aggregation or counts of affected users. In case you set user ID multiple times, only the last user ID will be used. You need to set the user ID yourself before each application launch, because this value isn't stored by the SDK between launches.

Disable all services at runtime

If you want to disable all App Center services at once, use the setEnabled() API. When disabled, the SDK won't forward any information to App Center.

import AppCenter from 'appcenter';

await AppCenter.setEnabled(false);

To enable all services at once again, use the same API but pass true as a parameter.

await AppCenter.setEnabled(true);

The state is persisted in the device's storage across application launches.

Disallow network requests

In the App Center SDK, network requests are allowed by default. If you want to send data that the App Center SDK collects by the user concern you can disallow automatic sending data.

await AppCenter.setNetworkRequestsAllowed(false);

In this case, the App Center SDK continues to collect data but it will be sent only when the network requests will be allowed.

await AppCenter.setNetworkRequestsAllowed(true);

Note

This value is retained between starts.

At any time, you can check whether sending data in the App Center SDK is allowed or not.

await AppCenter.isNetworkRequestsAllowed();

Note

The value saved in SharedPreferences is ignored until AppCenter is started on Android platform. It will return the last value set using setNetworkRequestsAllowed or true if the value wasn't changed before AppCenter start.

Change state of service in runtime

You can enable or disable the service at the runtime with following code:

await AppCenter.Analytics.setEnabled(false);

Check if App Center is enabled

You can also check if App Center is enabled or not.

const enabled = await AppCenter.isEnabled();

Check App Center SDK version at runtime

You can get the version of App Center SDK that you're currently using.

AppCenter.getSdkVersion();