maui
maui copied to clipboard
iOS AppDelegate - Override for PerformFetch is not available
Description
I'm currently migrating my Xamarin.Forms app to .NET MAUI.
Now I stuck on the BackgroundFetch on iOS.
In Xamarin I was able to override the PerformFetch method
public override async void PerformFetch(UIApplication application, Action<UIBackgroundFetchResult> completionHandler)
{
//Console.WriteLine("App is performing background fetch.");
try
{
await service?.RefreshAsync(application, completionHandler);
}
catch(Exception exc)
{
EventManager.LogError(exc, forceReport: true);
}
}
In the .NET MAUI AppDelegate, this method is not available for now.

I searched the docs, but the only thing I found was for Xamarin.Forms. https://docs.microsoft.com/en-us/dotnet/api/uikit.uiapplicationdelegate.performfetch?view=xamarin-ios-sdk-12
Steps to Reproduce
- Try to override the
PerformFetchmethod on iOS (AppDelegate)
Version with bug
6.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
Any
Did you find any workaround?
No response
Relevant log output
No response
From what I can tell this maybe wasn't ported. Opened a PR with what I think is the fix, but needs some feedback as I'm not really sure. Also, if this is the case, this will be added to .NET 7 at the earliest.
I think you can still implement it yourself by adding something like that method in my PR with the attribute above it. It doesn't need to be virtual then :)
Perfect, thank you @jfversluis
I believe this might be a candidate to be in the ConfigureLifecycleEvents as well? Basically,
events.AddiOS(ios => ios.PerformFetch((delegate) => RunMyBackgroundFetchCode());
@jfversluis any chance that the attached PR will be merged soon? Thank you!
Any updates? Or any workarounds?
@g0dpain Can you try something like this? Notice the Export tag and the lack of override. I'm able to call PerformFetch from an iOS 6 15.4 app. Works on Asp.net 7 and iOS 16 as well.
Added this to FinishedLaunching.
UIApplication.SharedApplication.SetMinimumBackgroundFetchInterval(UIApplication.BackgroundFetchIntervalMinimum);
[Export("application:performFetchWithCompletionHandler:")]
public void PerformFetch(UIApplication application, Action<UIBackgroundFetchResult> completionHandler)
{
// Perform task
// Inform system of fetch results
completionHandler(UIBackgroundFetchResult.NewData);
}
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
It is a large amount of work for a workaround, but I've been able to somewhat work around this by using Shiny.net's background jobs
You have to use the latest alpha packages for shiny, and the documentation is lacking; however, if you use their .NET template builder , you can get something that works in both platforms. It is kind of a philosophy change, once you start using 1 or 2 things from Shiny, you start consuming all their things. I've now converted my Json Config reader, background jobs, and local notifications to Shiny's implementation.