添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

I am trying to use background service in .NET MAUI app and here is my AppDelegate:

using Foundation;
using UIKit;
using UserNotifications;
namespace MyApp;
[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
    protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
    protected override async void PerformFetch(UIApplication application, UIBackgroundFetchResult completionHandler)
        // Perform your background fetch here
        completionHandler(UIBackgroundFetchResult.NewData);

but I get this error:

/Users/jassim/Projects/MyApp/MyApp/Platforms/iOS/AppDelegate.cs(35,35): Error CS0115: 'AppDelegate.PerformFetch(UIApplication, UIBackgroundFetchResult)': no suitable method found to override (CS0115) (MyApp)

Kindly help..

Thanks

Did you also try this?

protected override async void PerformFetch(UIApplication application, Action<UIBackgroundFetchResult> completionHandler)
. . .
												

Hi @Viorel @Jassim Al Rahma , you could try

public class AppDelegate : MauiUIApplicationDelegate
    protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
[Export("application:performFetchWithCompletionHandler:")]
public void PerformFetch(UIKit.UIApplication application, Action<UIKit.UIBackgroundFetchResult> completionHandler)
       // throw new System.NotImplementedException();

By the way, application:performFetchWithCompletionHandler: is deprecated.

It's recommended that you use BGAppRefreshTaskfor apps supporting iOS 13 and higher.

Hello,

This is a known issue reported at GitHub. Please see iOS AppDelegate - PerformFetch override #1419 and iOS AppDelegate - Override for PerformFetch is not available #7957

And it was fixed the in .Net8.0.0-preview.3.8149.

For the usage of App lifecycle, you could refer to App lifecycle - .NET MAUI | Microsoft Learn.

Best Regards,

Wenyan Zhang

If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.