public async Task<BackgroundTaskRegistrationResult> RegisterBackgroundTaskAsync(SdkConfiguration configuration)
{
BackgroundTaskRegistrationResult result = new BackgroundTaskRegistrationResult()
{
Success = IsBackgroundTaskRegistered,
Exception = null
};
if (!result.Success)
{
// Prompt user to accept the request
BackgroundAccessStatus backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync();
if (backgroundAccessStatus == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity
|| backgroundAccessStatus == BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity)
{
result = RegisterTimedBackgroundTask(configuration.BackgroundTimerClassName);
if (result.Success)
{
result = await RegisterAdvertisementWatcherBackgroundTaskAsync(configuration);
}
}
if (result.Success)
{
Logger.Debug("BackgroundTaskManager.RegisterBackgroundTask(): Registration successful");
}
}
else
{
Logger.Debug("BackgroundTaskManager.RegisterBackgroundTask(): Already registered");
}
return result;
}