为了账号安全,请及时绑定邮箱和手机立即绑定

swift location

始终无法进入回调函数 无法打印出坐标 求助

//

//  ViewController.swift

//  Swift Weather

//

//  Created by 许欢 on 15/3/27.

//  Copyright (c) 2015年 许欢. All rights reserved.

//


import UIKit

import CoreLocation


class ViewController: UIViewController,CLLocationManagerDelegate {

    let locationManager:CLLocationManager = CLLocationManager()

    

    override func viewDidLoad() {

        super.viewDidLoad()

        // Do any additional setup after loading the view, typically from a nib.

        locationManager.delegate = self

        locationManager.desiredAccuracy = kCLLocationAccuracyBest

        

        if ios8(){

            println("this is IOS8")

            locationManager.requestAlwaysAuthorization()

        }

        locationManager.startUpdatingLocation()

    }

    func ios8() ->Bool {

        let deviceVertion = UIDevice.currentDevice().systemVersion

        return UIDevice.currentDevice().systemVersion.hasPrefix("8")

    }

    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.

    }

    

    func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {

        var location:CLLocation = locations[locations.count-1] as CLLocation

        if location.horizontalAccuracy>0{

            println(location.coordinate.latitude)

            println(location.coordinate.longitude)

            updateWeatherInfo(location.coordinate.latitude,longitude:location.coordinate.longitude)

            

            locationManager.stopUpdatingLocation()

        }

    }

    func locationManager(manager: CLLocationManager!, didStartMonitoringForRegion region: CLRegion!){

        println("didStartMonitoringForRegion")


    }


    func locationManager(manager: CLLocationManager!, monitoringDidFailForRegion region: CLRegion!, withError error: NSError!) {

        println(error)

    }

    func updateWeatherInfo(latitude:CLLocationDegrees,longitude:CLLocationDegrees){

        //        let manager =

        let manager = AFHTTPRequestOperationManager()

        let url = "http://api.openweathermap.org/data/2.5/weather"

        println(url)

        

        let params = ["lat": 39.26, "lon": 41.03, "cnt":0]

        println(params)

        

        manager.GET(url,

            parameters: params,

            success: { (operation: AFHTTPRequestOperation!,

                responseObject: AnyObject!) in

                println("JSON: " + responseObject.description!)

            },

            failure: { (operation: AFHTTPRequestOperation!,

                error: NSError!) in

                println("Error: " + error.localizedDescription) 

        })

               

    }

}



正在回答

1 回答

info.plist的文件不要弄错了。

0 回复 有任何疑惑可以回复我~
#1

黑山白水

确认是对的,为什么还是进不去函数呢
2015-12-04 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Swift Weather APP
  • 参与学习       35561    人
  • 解答问题       241    个

本课程将带领大家使用Swift语言开发一个完整的天气 iOS APP

进入课程

swift location

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信