【发布时间】:2016-07-13 19:53:54
【问题描述】:
我正在尝试设置警报,一旦用户输入特定位置,警报就会弹出并允许用户“签到”。用户签入应用程序后,通知 api 端点用户已成功签入。这是我第一次使用地理围栏和核心定位。我了解如何设置它的基本概念,但不完全确定签到警报和地理围栏如何结合在一起。这是我的代码:
import UIKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate{
var manager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
// Core Location
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.requestWhenInUseAuthorization()
manager.startUpdatingLocation()
var latitude: CLLocationDegrees = 43.039278
var longitude: CLLocationDegrees = -87.932479
var center: CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
var radius: CLLocationDistance = CLLocationDistance(10.0)
var identifier: String = "storeID"
var geoRegion: CLCircularRegion = CLCircularRegion(center: center, radius: radius, identifier: identifier)
}
func showSimpleAlertWithTitle(title: String!, message: String!, viewController: UIViewController) {
let alert = UIAlertController(title: title, message: message, preferredStyle: .Alert)
let action = UIAlertAction(title: "Check-In", style: .Cancel , handler: nil)
alert.addAction(action)
viewController.presentViewController(alert, animated: true, completion: nil)
}
}
【问题讨论】:
标签: ios swift geolocation core-location