【发布时间】: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