Xamarin iOS 使用 BackgroundTasks 刷新和维护应用程序

Xamarin iOS Refreshing And Maintaining App Using BackgroundTasks

这是在 Xamarin.iOS 中使用 BGTaskScheduler 的尝试。

我已经尝试 运行 来自 https://github.com/xamarin/ios-samples/tree/master/ios13/RefreshingAndMaintainingYourAppUsingBackgroundTasks 的示例应用程序。

原生版本(Swift 和 Objective C)工作正常。

平台详情

预期结果: 应用程序在后台定期更新

实际结果:没有触发回调。控制台无痕迹。


我通过为 BGTaskScheduler.I 创建一个可绑定库来解决它,

  1. 创建了一个 iOS Objective C 静态库,其中包含足够的 API 来注册、取消请求。 (Swift 在 Bindable Library 项目中没有太多支持)
  2. 为上述库创建了一个 fat 文件。
  3. 创建了 Xamarin.iOS 可绑定库项目并引用了创建的 fat 文件。
  4. 定义了库中的API定义并生成了 .dll。
  5. 能够在 Xamarin.iOS 项目中使用此 .dll 文件并且 BGTaskScheduler 工作正常。

  1. 是否可以从本机 swift/objective C 代码创建可绑定库?

Yes.Objective C is preferred for the same

  1. Xamarin 可绑定库如何工作?

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

  1. 它真的是在调用本机 API(如 JNI)还是它映射了相应的 Xamarin API?

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

  1. 是否可以在没有源代码或本机库二进制文件的情况下创建可绑定库?

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

  1. 是否必须等待官方 Xamarin.MaciOS SDK 中的错误修复?

Not really actually . :)