状况:
我遵循了以下教程:
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上。在您看来是什么导致了这个问题,我该如何解决?
答案 0 :(得分:2)
您没有显示用于设置CL的代码 - 这可能就是您的问题所在。
你编辑过info.plist吗?
您是否请求许可?
您是否在CL管理器上调用了其中一个启动函数?