Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS AppDelegate - Override for PerformFetch is not available #7957

Closed
AndreasReitberger opened this issue Jun 12, 2022 · 8 comments · Fixed by #7982
Closed

iOS AppDelegate - Override for PerformFetch is not available #7957

AndreasReitberger opened this issue Jun 12, 2022 · 8 comments · Fixed by #7982
Labels
area-core-lifecycle XPlat and Native UIApplicationDelegate/Activity/Window lifecycle events fixed-in-8.0.0-preview.3.8149 Look for this fix in 8.0.0-preview.3.8149! platform/iOS 🍎 proposal/open t/bug Something isn't working t/enhancement ☀️ New feature or request

Comments

@AndreasReitberger
Copy link

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

@AndreasReitberger AndreasReitberger added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels Jun 12, 2022
@jfversluis jfversluis added area-core-lifecycle XPlat and Native UIApplicationDelegate/Activity/Window lifecycle events platform/iOS 🍎 and removed s/needs-verification Indicates that this issue needs initial verification before further triage will happen labels Jun 13, 2022
@jfversluis
Copy link
Member

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 :)

@AndreasReitberger
Copy link
Author

Perfect, thank you @jfversluis

@edgiardina
Copy link

edgiardina commented Aug 14, 2022

I believe this might be a candidate to be in the ConfigureLifecycleEvents as well? Basically,

events.AddiOS(ios => ios.PerformFetch((delegate) => RunMyBackgroundFetchCode());

@AndreasReitberger
Copy link
Author

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

@g0dpain
Copy link

g0dpain commented Nov 28, 2022

Any updates? Or any workarounds?

@faceoffers28
Copy link

faceoffers28 commented Nov 28, 2022

@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);
    }

@mattleibow mattleibow added this to the Backlog milestone Feb 4, 2023
@ghost
Copy link

ghost commented Feb 4, 2023

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.

@edgiardina
Copy link

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.

@samhouts samhouts modified the milestones: Backlog, .NET 8 Planning Mar 17, 2023
@samhouts samhouts added the fixed-in-8.0.0-preview.3.8149 Look for this fix in 8.0.0-preview.3.8149! label Apr 12, 2023
@ghost ghost locked as resolved and limited conversation to collaborators May 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-core-lifecycle XPlat and Native UIApplicationDelegate/Activity/Window lifecycle events fixed-in-8.0.0-preview.3.8149 Look for this fix in 8.0.0-preview.3.8149! platform/iOS 🍎 proposal/open t/bug Something isn't working t/enhancement ☀️ New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants