【发布时间】:2016-08-15 17:45:11
【问题描述】:
情况:
我按照以下教程进行操作:
https://www.raywenderlich.com/95014/geofencing-ios-swift
问题:
以下函数永远不会被触发:
AppDelegate.swift
func locationManager(manager: CLLocationManager, didEnterRegion region: CLRegion) {
if region is CLCircularRegion {
handleRegionEvent(region)
}
}
func locationManager(manager: CLLocationManager, didExitRegion region: CLRegion) {
if region is CLCircularRegion {
handleRegionEvent(region)
}
}
func handleRegionEvent(region: CLRegion!) {
print("Geofence triggered!")
// Show an alert if application is active
if UIApplication.sharedApplication().applicationState == .Active {
if let message = notefromRegionIdentifier(region.identifier) {
if let viewController = window?.rootViewController {
showSimpleAlertWithTitle("Congratulations", message: "You just found: " + message , viewController: viewController)
}
}
} else {
// Otherwise present a local notification
let notification = UILocalNotification()
notification.alertBody = "You just found: " + notefromRegionIdentifier(region.identifier)!
notification.soundName = "Default";
UIApplication.sharedApplication().presentLocalNotificationNow(notification)
}
}
问题:
本教程是为 iOS 8 编写的。我目前使用的是 iOS 9.3。在您看来是什么导致了这个问题,我该如何解决?
【问题讨论】:
-
编辑:代码在 XCode 模拟器中运行良好(我可以使用 gpx 文件在 XCode 中模拟从 A 点到 B 点的移动),但在我的 iPhone 上却不行……为什么?肯定有解决方案。
标签: ios swift core-location