On iOS, we can use Background Fetch to implement background tasks. However, it’s important to note that the execution time and frequency of iOS background tasks are uncertain and depend on the system’s scheduling.
Enabling Background Fetch:
Add the following key-value pair to your Info.plist file:
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
</array>
Ensure the Background Fetch Interval:
Set the minimum background fetch interval to the desired frequency in the FinishedLaunching method.
UIApplication.SharedApplication.SetMinimumBackgroundFetchInterval(UIApplication.BackgroundFetchIntervalMinimum);
if you would like to set interval as one day, the value should be 86400
implementing Background Fetch:
Implement the PerformFetch method in your AppDelegate:
public override void PerformFetch(UIApplication application, Action<UIBackgroundFetchResult> completionHandler)
{
// Call your background task here
RecordTransaction();
// Call the completion handler
completionHandler(UIBackgroundFetchResult.NewData);
}
Leave a comment