第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

老師,請問我為什么一直顯示地理位置信息不可用啊?

import UIKit

import CoreLocation


class WeatherViewController:UIViewController, CLLocationManagerDelegate {

? ? let locationManger = CLLocationManager()

?? ?

? ? @IBOutlet weak var location: UILabel!

? ? @IBOutlet weak var icon: UIImageView!

? ? @IBOutlet weak var temperature: UILabel!

? ? @IBOutlet weak var loading: UILabel!

? ? @IBOutlet weak var loadingIndicator: UIActivityIndicatorView!

?? ?

? ? override func viewDidLoad() {

? ? ? ? super.viewDidLoad()

?? ? ? ?

? ? ? ? locationManger.delegate = self

? ? ? ? locationManger.desiredAccuracy = kCLLocationAccuracyBest

?? ? ? ?

? ? ? ? self.loadingIndicator.startAnimating()

?? ? ? ?

? ? ? ? let backgroud = UIImage(named: "background")

? ? ? ? self.view.backgroundColor = UIColor(patternImage: backgroud!)

?? ? ? ?

? ? ? ? if(iOS8()) {

? ? ? ? ? ? locationManger.requestAlwaysAuthorization()

? ? ? ? }

? ? ? ? locationManger.startUpdatingLocation()

? ? }

?? ?

? ? func iOS8() -> Bool {

? ? ? ? if(UIDevice.currentDevice().systemVersion == "8.0") || (UIDevice.currentDevice().systemVersion == "8.0.1") || (UIDevice.currentDevice().systemVersion == "8.0.2") || (UIDevice.currentDevice().systemVersion == "8.1") || (UIDevice.currentDevice().systemVersion == "8.1.1") || (UIDevice.currentDevice().systemVersion == "8.1.2") || (UIDevice.currentDevice().systemVersion == "8.1.3") {

? ? ? ? ? ? return true

? ? ? ? }

? ? ? ? else {

? ? ? ? ? ? return false

? ? ? ? }

? ? }

?? ?

? ? 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)

? ? ? ? ? ? locationManger.stopUpdatingLocation()

? ? ? ? }

? ? }

?? ?

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

? ? ? ? let manager = AFHTTPRequestOperationManager()

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

? ? ? ? let params = ["lat": latitude, "lon": longitude, "cnt": 0]

? ? ? ? manager.GET(url, parameters: params,

? ? ? ? ? ? success: {(operation: AFHTTPRequestOperation!, responseObject: AnyObject!) in println("JSON: " + responseObject.description!);self.updateUISuccess(responseObject as NSDictionary!)

? ? ? ? ? ? },

? ? ? ? ? ? failure: {(operation: AFHTTPRequestOperation!, error: NSError!) in println("Error:" + error.localizedDescription)

? ? ? ? })

? ? }

?? ?

? ? func updateUISuccess(jsonResult: NSDictionary!) {

? ? ? ? self.loadingIndicator.hidden = true

? ? ? ? self.loadingIndicator.stopAnimating()

? ? ? ? self.loading.text = nil

?? ? ? ?

? ? ? ? if let tempResult = jsonResult["main"]?["temp"]? as? Double {

? ? ? ? ? ? var temperature: Double

? ? ? ? ? ? if(jsonResult["sys"]?["country"]? as String == "US") {

? ? ? ? ? ? ? ? temperature = round(((tempResult - 273.15) * 1.8) + 32)

? ? ? ? ? ? }

? ? ? ? ? ? else {

? ? ? ? ? ? ? ? temperature = round(tempResult - 273.15)

? ? ? ? ? ? }

? ? ? ? ? ? self.temperature.text = "\(temperature)?"

? ? ? ? ? ? var name = jsonResult["name"]? as String

? ? ? ? ? ? self.location.text = "\(name)"

?? ? ? ? ? ?

? ? ? ? ? ? var condition = (jsonResult["weather"]? as NSArray)[0]["id"]? as Int

? ? ? ? ? ? var sunrise = jsonResult["sys"]?["sunrise"]? as Double

? ? ? ? ? ? var sunset = jsonResult["sys"]?["sunset"]? as Double

?? ? ? ? ? ?

? ? ? ? ? ? var nightTime = false

? ? ? ? ? ? var now = NSDate().timeIntervalSince1970

?? ? ? ? ? ?

? ? ? ? ? ? if(now < sunrise || now > sunset) {

? ? ? ? ? ? ? ? nightTime = true

? ? ? ? ? ? }

? ? ? ? ? ? self.updateWeatherIcon(condition, nightTime: nightTime)

? ? ? ? }

? ? ? ? else {

? ? ? ? ? ? self.loading.text = "天氣信息不可用"

? ? ? ? }

? ? }

?? ?

? ? func updateWeatherIcon(condition: Int, nightTime: Bool) {

? ? ? ? if(condition < 300) {

? ? ? ? ? ? if nightTime {

? ? ? ? ? ? ? ? self.icon.image = UIImage(named: "tstorm1_night")

? ? ? ? ? ? }

? ? ? ? ? ? else {

? ? ? ? ? ? ? ? self.icon.image = UIImage(named: "tsorm1")

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? else if(condition < 500) {

? ? ? ? ? ? self.icon.image = UIImage(named: "light_rain")

? ? ? ? }

? ? ? ? else if(condition < 600) {

? ? ? ? ? ? self.icon.image = UIImage(named: "shower3")

? ? ? ? }

? ? ? ? else if(condition < 700) {

? ? ? ? ? ? self.icon.image = UIImage(named: "snow4")

? ? ? ? }

? ? ? ? else if(condition < 771) {

? ? ? ? ? ? if nightTime {

? ? ? ? ? ? ? ? self.icon.image = UIImage(named: "fog_night")

? ? ? ? ? ? }

? ? ? ? ? ? else {

? ? ? ? ? ? ? ? self.icon.image = UIImage(named: "fog")

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? else if(condition < 800) {

? ? ? ? ? ? self.icon.image = UIImage(named: "tstorm3")

? ? ? ? }

? ? ? ? else if(condition == 800) {

? ? ? ? ? ? if nightTime {

? ? ? ? ? ? ? ? self.icon.image = UIImage(named: "sunny_night")

? ? ? ? ? ? }

? ? ? ? ? ? else {

? ? ? ? ? ? ? ? self.icon.image = UIImage(named: "sunny")

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? else if(condition < 804) {

? ? ? ? ? ? if nightTime {

? ? ? ? ? ? ? ? self.icon.image = UIImage(named: "cloudy2_night")

? ? ? ? ? ? }

? ? ? ? ? ? else {

? ? ? ? ? ? ? ? self.icon.image = UIImage(named: "cloudy2")

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? else if(condition == 804) {

? ? ? ? ? ? self.icon.image = UIImage(named: "overcast")

? ? ? ? }

? ? ? ? else if((condition >= 900) || (condition > 904 && condition < 1000)) {

? ? ? ? ? ? self.icon.image = UIImage(named: "tstorm3")

? ? ? ? }

? ? ? ? else if(condition == 903) {

? ? ? ? ? ? self.icon.image = UIImage(named: "snow5")

? ? ? ? }

? ? ? ? else if(condition == 904) {

? ? ? ? ? ? self.icon.image = UIImage(named: "sunny")

? ? ? ? }

? ? ? ? else {

? ? ? ? ? ? self.icon.image = UIImage(named: "dunno")

? ? ? ? }

? ? }

?? ?

? ? func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {

? ? ? ? self.loading.text = "地理位置信息不可用"

? ? }

}


正在回答

1 回答

具體原因你可以打印輸出下

func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {

? ? ? ? self.loading.text = "地理位置信息不可用"

? ? }

給出的error信息看看

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消
Swift Weather APP
  • 參與學(xué)習(xí)       35553    人
  • 解答問題       241    個

本課程將帶領(lǐng)大家使用Swift語言開發(fā)一個完整的天氣 iOS APP

進(jìn)入課程

老師,請問我為什么一直顯示地理位置信息不可用???

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號