SensorbergSDK.BackgroundTaskManager.CheckIfBackgroundFilterUpdateIsRequired C# (CSharp) Method

CheckIfBackgroundFilterUpdateIsRequired() public static method

Checks if the background filters are up-to-date or not. To update the filters, unregister and register background task again (call BackgroundTaskManager.UpdateBackgroundTaskAsync()).
public static CheckIfBackgroundFilterUpdateIsRequired ( ) : bool
return bool
        public static bool CheckIfBackgroundFilterUpdateIsRequired()
        {
            bool isRequired = SdkData.BackgroundFilterUpdateRequired;

            if (!isRequired && !string.IsNullOrEmpty(SdkData.LayoutBeaconId1Hash))
            {
                string upToDateHash = LayoutManager.CreateHashOfBeaconId1SInLayout(ServiceManager.LayoutManager.Layout);

                if (!string.IsNullOrEmpty(upToDateHash)
                    && !SdkData.LayoutBeaconId1Hash.Equals(upToDateHash))
                {
                    SdkData.LayoutBeaconId1Hash = upToDateHash;
                    SdkData.BackgroundFilterUpdateRequired = true;
                    isRequired = true;
                }
            }

            return isRequired;
        }

Usage Example

        public async Task <BackgroundTaskRegistrationResult> UpdateBackgroundTaskIfNeededAsync()
        {
            BackgroundTaskRegistrationResult result = new BackgroundTaskRegistrationResult()
            {
                Success   = true,
                Exception = null
            };

            if (BackgroundTaskManager.CheckIfBackgroundFilterUpdateIsRequired())
            {
                result = await _backgroundTaskManager.UpdateBackgroundTaskAsync(Configuration);
            }

            SdkData.BackgroundTaskEnabled = true;
            return(result);
        }