Search code examples
iosxamarin.iosbackground-processios13

Xamarin iOS Refreshing And Maintaining App Using BackgroundTasks


This is an attempt to use BGTaskScheduler in Xamarin.iOS.

I have tried to run the sample Application from https://github.com/xamarin/ios-samples/tree/master/ios13/RefreshingAndMaintainingYourAppUsingBackgroundTasks .

Native version (both Swift and Objective C) is working fine.

Platform Details

  • Mac OS : Mac OS Mojave 10.14.6
  • XCode : Version 11.1
  • Device : iPhone 8 Plus | OS 13.1.2
  • Visual Studio : VS for Mac 8.3.1

Expected result : Periodic updates from the App in the background

Actual Result : No callback triggered. No traces in the console.


  • Is it possible to create a bindable library from the native swift/objective C code ?

  • Hows Xamarin Bindable Library works ?

  • Is it really calling the native API (like JNI) or Is it mapping the corresponding Xamarin APIs ?

  • Is it possible to create a bindable library without the source code or native library binary ?

  • Is it mandatory to wait for a bug fix in the official Xamarin.MaciOS SDK ?


Solution

  • I resolved it by creating a Bindable Library for BGTaskScheduler.I did ,

    1. Created a iOS Objective C static library containing , enough APIs to register , cancel requests. (Swift is not much supported in Bindable Library projects)
    2. Created a fat file for the above library.
    3. Created Xamarin.iOS Bindable Library project and referenced the fat file created.
    4. Defined the APIDefinitions in the Library and .dll generated.
    5. Able to use this .dll file in the Xamarin.iOS project and BGTaskScheduler is working fine.

    1. Is it possible to create a bindable library from the native swift/objective C code ?

    Yes.Objective C is preferred for the same

    1. Hows Xamarin Bindable Library works ?.

    Bindable library creates a well defined interface between Xamarin.iOS and the Native APIs.Developer can access the native APIs through this layer.

    1. Is it really calling the native API (like JNI) or Is it mapping the corresponding Xamarin APIs ?

    Yes.It is like JNI.When we call the exported method in the APIDefinitions , its actually calls the Native method.

    1. Is it possible to create a bindable library without the source code or native library binary ?

    You need to properly link the required frameworks in the static library.

    1. Is it mandatory to wait for a bug fix in the official Xamarin.MaciOS SDK ?

    Not really actually . :)