question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

iOS AppDelegate - Override for PerformFetch is not available

See original GitHub issue

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.

image

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

  1. Try to override the PerformFetch method 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

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
faceoffers28commented, Feb 4, 2023

@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);
    }
1reaction
AndreasReitbergercommented, Nov 14, 2022

@jfversluis any chance that the attached PR will be merged soon? Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

no suitable method found to override
Hi, I am trying to use background service in .NET MAUI app and here is my AppDelegate: using Foundation; using UIKit; ...
Read more >
iOS: UIBackgroundFetch - PerformFetch not called
On an iOS device, this method is called unpredictably by the OS. There are many factors that go into how often this method...
Read more >
application(_:performFetchWithCompletionHandler:)
Tells the app that it can begin a fetch operation if it has data to download. ... For apps supporting iOS 13 and...
Read more >
Updating data in the background
Enter the following code, again, in the AppDelegate class: private int updateCount; public override void PerformFetch (UIApplication ...
Read more >
Utilizing the iOS Background with Xamarin: Part 1 - Atomic Spin
Implement the fetch handler. The final step is to implement the PerformFetch delegate method in your AppDelegate declaration. This is the method ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found