我也跟着下面的教程:
https://www.raywenderlich.com/95014/geofencing-ios-swift
問題:
下面的功能不被觸發:
APPD elegate.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上...爲什麼?確實存在解決方案。 – Coder1000