Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Having trouble getting BackgroundFetch to work in Xamarin Forms iOS.

$
0
0

Hi,
I've been working on this for days now. I run our XF iOS app on a real device in debug mode. After it starts up, I press Home and the app goes to sleep - a debug statement in OnSleep tells me it got there. Next, I leave it alone and watch for the debug statement that tells me it got to PerformFetch. After 18 hours it still did not appear.
I know that iOS controls when it does a PerformFetch. But seriously, 18 hours and nothing?
Could iOS have messed up its timer or the minimum time for our app? Is there a way to reset it or does that happen when I reload a newly compiled version? Or do I have to change the actual version number?

For those that have read this far, you probably have some questions. Here are my settings and some snippets of my code.

In Info.plist, in Background Modes, I selected Enable Background Modes and Background Fetch.

On the device:
1) in Settings, I enabled BackgroundAppRefresh for the app.
2) In Settings, under the app, I enabled BackgroundAppRefresh

`
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{

UIApplication.SharedApplication.SetMinimumBackgroundFetchInterval(UIApplication.BackgroundFetchIntervalMinimum);
}

public override async void PerformFetch(UIApplication application, Action<UIBackgroundFetchResult> completionHandler)
{
try
{
    var result = UIBackgroundFetchResult.NoData;
        bool bOK = await Util.RequestProjectsFromWebService(user);        
    result = UIBackgroundFetchResult.NewData;
        }
        catch (Exception ex)
        {
    result = UIBackgroundFetchResult.Failed;
        }
        finally
        {
               completionHandler(result);
        }

}
`
I'll be away for a few days, so it will be interesting to see how the app performs during that time.

Any ideas on how to get into PerformFetch would be much appreciated.
Regards,
Will


Viewing all articles
Browse latest Browse all 89864

Trending Articles