【问题标题】:How can plugins be used in another plugin's callback in the background?插件如何在后台用于另一个插件的回调?
【发布时间】:2020-07-01 22:38:19
【问题描述】:

我在我的 Flutter 应用程序中使用了这个 background_locator 插件和一个 geofencing 插件。在 background_locator 插件的位置回调函数中,我使用地理围栏插件创建地理围栏。这在 Android 上运行良好。在 iOS 上,background_locator 插件正常运行,但在回调中调用地理围栏方法无效。在回调之外调用地理围栏方法没有问题。

我找到了一些解决此问题的资源:@​​987654323@ 和 https://github.com/flutter/engine/pull/7843 并相应地更改了我的 AppDelegate.swift 中的代码,但这个问题仍然存在。任何建议表示赞赏!

下面是我的 AppDelegate.swift

import UIKit
import Flutter
import GoogleMaps

func registerPlugins(registry: FlutterPluginRegistry) -> () {
  if (!registry.hasPlugin("BackgroundLocatorPlugin")) {
    BackgroundLocatorPlugin.register(with: registry.registrar(forPlugin: "BackgroundLocatorPlugin"))
  } 
  if (!registry.hasPlugin("GeofencingPlugin")) {
    GeofencingPlugin.register(with: registry.registrar(forPlugin: "GeofencingPlugin"))
  }
  if (!registry.hasPlugin("FlutterLocalNotificationsPlugin")) {
    FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
  }
  if (!registry.hasPlugin("FLTSharedPreferencesPlugin")) {
    FLTSharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "FLTSharedPreferencesPlugin"))
  }
  if (!registry.hasPlugin("FlutterSecureStoragePlugin")) {
    FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin"))
  }
}

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GMSServices.provideAPIKey("$GOOGLE_MAPS_API_KEY")

    GeneratedPluginRegistrant.register(with: self)

    GeofencingPlugin.setPluginRegistrantCallback(registerPlugins)
    BackgroundLocatorPlugin.setPluginRegistrantCallback(registerPlugins)

    // iOS notification setup
    if #available(iOS 10.0, *) {
      UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
    }
    // Prevent "old" notifications showing up after reinstallation
    if(!UserDefaults.standard.bool(forKey: "Notification")) {
      UIApplication.shared.cancelAllLocalNotifications()
      UserDefaults.standard.set(true, forKey: "Notification")
    }
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

【问题讨论】:

  • 伊丽莎白你是怎么解决的?请帮帮我
  • 我的 firestore 流查询无法与 background_locator 插件一起使用

标签: ios flutter geolocation background-process geofencing


【解决方案1】:

我遇到了“FlutterGeofencing”的问题,即应用程序将捕获异常“无法设置 registerPlugins”并通过设置回调解决问题

override func application(
       _ application: UIApplication,
       didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
   ) -> Bool {
       GeneratedPluginRegistrant.register(with: self)
       GeofencingPlugin.setPluginRegistrantCallback({_ in
       })
       return super.application(application, didFinishLaunchingWithOptions: launchOptions)
   }

【讨论】:

    猜你喜欢
    • 2015-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-23
    • 1970-01-01
    • 1970-01-01
    • 2010-11-30
    相关资源
    最近更新 更多