swift 笔记 保持后台的办法

来源:互联网 发布:mysql字段默认time() 编辑:程序博客网 时间:2024/06/03 15:43
class ViewController: UIViewController,CLLocationManagerDelegate,GCDAsyncUdpSocketDelegate{    let locationManager = CLLocationManager()    override func viewDidLoad() {        super.viewDidLoad()        locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers        locationManager.delegate=self        locationManager.requestAlwaysAuthorization()    }}

开始GPS定位之后,程序就可以在后台保持运行.

ipad mini2真机测试一晚上掉电5%


    func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {        var location:CLLocation = locations[locations.count-1] as CLLocation        if(location.horizontalAccuracy>0){            let gps="GPS信息:\n经度:\(location.coordinate.latitude)\n纬度:\(location.coordinate.longitude)"            println(gps)        }    }
需要在info.plist文件中加入以下几条

Privacy - Location Usage Description    我们需要访问您的地理位置信息

NSLocationAlwaysUsageDescription    我们需要访问您的地理位置信息

Required background modes      App registers for location updates


0 0
原创粉丝点击