【发布时间】:2018-07-30 16:04:48
【问题描述】:
我正在尝试开发一个应用程序,当我进入之前创建的本地区域时,通知此事件。我已经阅读了很多讨论,但我仍然感到困惑。我正在这个社区的帮助下开发这个应用程序,因为我对 swift 也很陌生。开发的应用程序在处于活动状态或在后台运行时效果很好,但如果它关闭则不起作用。事实上我想要那个s.o。当 iphone 进入之前创建的本地区域时唤醒我的应用程序(用于执行某些操作,例如通知)。阅读苹果的文档,我发现 lauchOptions 对我的问题很重要。所以在上面,我在我的 AppDelegate 类中发布了应用程序函数的代码。
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:
[UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application
launch.
registerForPushNotifications()
if launchOptions?[UIApplicationLaunchOptionsKey.location] != nil {
if locationManager == nil {
locationManager = CLLocationManager()
locationManager?.delegate = self
locationManager?.distanceFilter = 10
locationManager?.desiredAccuracy = kCLLocationAccuracyBest
locationManager?.allowsBackgroundLocationUpdates = true
locationManager?.startUpdatingLocation()
Logger.write(text: "app opened by s.o.", to: logFile)
}
} else {
locationManager?.delegate = self
locationManager?.distanceFilter = 10
locationManager?.desiredAccuracy = kCLLocationAccuracyBest
locationManager?.allowsBackgroundLocationUpdates = true
locationManager?.startUpdatingLocation()
if CLLocationManager.authorizationStatus() == .notDetermined {
locationManager?.requestAlwaysAuthorization()
}
else if CLLocationManager.authorizationStatus() == .denied {
}
else if CLLocationManager.authorizationStatus() == .authorizedAlways {
locationManager?.requestAlwaysAuthorization()
}
}
return true
}
根据找到的其他讨论,我已经实现了此代码,但正如字符串“由 s.o. 打开的应用程序”之前所说的那样。永远不会写在我的日志文件上。我怎么解决这个问题?提前谢谢大家!
【问题讨论】:
标签: ios swift geolocation location core-location