国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼

這篇具有很好參考價(jià)值的文章主要介紹了iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

?1.獲取用戶當(dāng)前所在的位置

在infi中點(diǎn)擊加號(hào),選擇權(quán)限:當(dāng)用戶使用app的時(shí)候獲取位置權(quán)限.

iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼,ios,swift,cocoapods,開發(fā)語言,xcode

填寫使用位置權(quán)限的目的.

iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼,ios,swift,cocoapods,開發(fā)語言,xcode

?2.獲取用戶的經(jīng)緯度.

ViewController:

import UIKit
import CoreLocation

class ViewController: UIViewController, CLLocationManagerDelegate {    //遵循CLLocationManagerDelegate協(xié)議
    //位置管理器
    let locationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        locationManager.requestWhenInUseAuthorization()    //請(qǐng)求當(dāng)用戶正在使用app的時(shí)候允許后臺(tái)得到用戶位置.只會(huì)彈出來一次
        locationManager.delegate = self    //位置管理器代理人是view controller對(duì)象.希望view controller能通過實(shí)現(xiàn)CLLocationManagerDelegate協(xié)議中的方法,獲取到當(dāng)前用戶位置信息
        locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers    //設(shè)置需要的位置精度(三公里誤差精度)
        locationManager.requestLocation()    //請(qǐng)求用戶位置
        
        
    }
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {  //requesLocation請(qǐng)求到了的話會(huì)執(zhí)行這個(gè)方法
        let lon = locations[0].coordinate.longitude   //精度.因?yàn)閘ocation可能實(shí)時(shí)變化(地圖app),所以是一個(gè)數(shù)組.我們只需要使用第一個(gè)獲取到的位置.
        let lat = locations[0].coordinate.latitude    //緯度
        print(lon)
        print(lat)
    }
    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {    //requesLocation請(qǐng)求失敗的話會(huì)執(zhí)行這個(gè)方法
        print(error)
    }


}

iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼,ios,swift,cocoapods,開發(fā)語言,xcode

?3.通過第三方服務(wù)獲取當(dāng)前天氣

(1)安裝cocoapods

https://dev.qweather.com/

在網(wǎng)站中可以找到,當(dāng)向 https://devapi.qweather.com/v7/weather/now?[請(qǐng)求參數(shù)] 發(fā)送請(qǐng)求時(shí),就可以得到當(dāng)前天氣.

通過依賴管理工具cocoapods命令行工具進(jìn)行依賴管理.在終端里對(duì)它進(jìn)行下載并安裝,

在Mac的啟動(dòng)臺(tái)上找到「終端」應(yīng)用,或者在觸控板上通過四指聚合來打開「啟動(dòng)臺(tái)—終端」。

在命令行輸入

sudo gem install cocoapods

(以超級(jí)管理員的身份,安裝cocoapods這個(gè)應(yīng)用.)

輸入電腦開機(jī)密碼.

iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼,ios,swift,cocoapods,開發(fā)語言,xcode

?等待安裝成功.

iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼,ios,swift,cocoapods,開發(fā)語言,xcode

?這里可能出現(xiàn)Error installing cocoapods:
The last version of activesupport (>= 5.0, < 8) to support your Ruby & RubyGems was 6.1.7.6. Try installing it with `gem install activesupport -v 6.1.7.6` and then running the current command again
activesupport requires Ruby version >= 2.7.0. The current ruby version is 2.6.10.210.

這個(gè)bug,解決方式請(qǐng)參照博客:https://www.cnblogs.com/lysboke/p/17678896.html

(2)安裝功能包

在cocoapods官網(wǎng)https://cocoapods.org/的搜索欄搜索Alamofire.點(diǎn)擊進(jìn)入.

iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼,ios,swift,cocoapods,開發(fā)語言,xcode

?用cocoapods安裝Alamofire.

在終端中輸入cd空格,將項(xiàng)目文件夾Weather拖入到cd后面.點(diǎn)擊回車.

iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼,ios,swift,cocoapods,開發(fā)語言,xcode

?終端輸入

pod init

等待.完成之后打開Weather文件夾,發(fā)現(xiàn)成功創(chuàng)建Podfile文件.

iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼,ios,swift,cocoapods,開發(fā)語言,xcode

iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼,ios,swift,cocoapods,開發(fā)語言,xcode

?將Podfile拖入Xcode,Podfile自動(dòng)彈出.

iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼,ios,swift,cocoapods,開發(fā)語言,xcode

加入代碼:

  pod 'Alamofire'

保存并關(guān)閉Podfile.

iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼,ios,swift,cocoapods,開發(fā)語言,xcode

?在終端輸入命令安裝功能包:

pod install

iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼,ios,swift,cocoapods,開發(fā)語言,xcode

?關(guān)閉Xcode,從Weather文件中打開Weather.xcworkspace,可以看到項(xiàng)目結(jié)構(gòu)如下.

iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼,ios,swift,cocoapods,開發(fā)語言,xcode

?4.利用和風(fēng)API獲取當(dāng)前位置的天氣信息

注冊(cè)和風(fēng)天氣賬號(hào).在和風(fēng)天氣中創(chuàng)建一個(gè)免費(fèi)的新項(xiàng)目.

https://console.qweather.com/#/apps/create-app/create

iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼,ios,swift,cocoapods,開發(fā)語言,xcode

?得到key.

編寫代碼得到當(dāng)前經(jīng)緯度下的天氣數(shù)據(jù)信息.

import UIKit
import CoreLocation
import Alamofire   //引入和風(fēng)API包

class ViewController: UIViewController, CLLocationManagerDelegate {    //遵循CLLocationManagerDelegate協(xié)議
    //位置管理器
    let locationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        locationManager.requestWhenInUseAuthorization()    //請(qǐng)求當(dāng)用戶正在使用app的時(shí)候允許后臺(tái)得到用戶位置.只會(huì)彈出來一次
        locationManager.delegate = self    //位置管理器代理人是view controller對(duì)象.希望view controller能通過實(shí)現(xiàn)CLLocationManagerDelegate協(xié)議中的方法,獲取到當(dāng)前用戶位置信息
        locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers    //設(shè)置需要的位置精度(三公里誤差精度)
        locationManager.requestLocation()    //請(qǐng)求用戶位置
        
        
    }
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {  //requesLocation請(qǐng)求到了的話會(huì)執(zhí)行這個(gè)方法
        let lon = locations[0].coordinate.longitude   //精度.因?yàn)閘ocation可能實(shí)時(shí)變化(地圖app),所以是一個(gè)數(shù)組.我們只需要使用第一個(gè)獲取到的位置.
        let lat = locations[0].coordinate.latitude    //緯度
        //print(lon)
        //print(lat)
        AF.request("https://devapi.qweather.com/v7/weather/now?location=\(lon),\(lat)&key=a91848aaab484a3599a703b139dfe87b").responseJSON { response in
            if let data = response.value{
                print(data)
            }
        }      //請(qǐng)求和風(fēng)API的網(wǎng)址,得到當(dāng)前位置的天氣
    }
    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {    //requesLocation請(qǐng)求失敗的話會(huì)執(zhí)行這個(gè)方法
        print(error)
    }
}

為了在測(cè)試中使用http傳輸,在Info中新增一個(gè)key和Value:App Transport Security Settings,在它里邊再添加一個(gè)Allow Arbitrary Loads,Value設(shè)置為Yes.

iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼,ios,swift,cocoapods,開發(fā)語言,xcode

?5.解析和風(fēng)API返回的JSON數(shù)據(jù)

在Xcode中的Podfile中添加如下:

pod 'SwiftyJSON', '~> 4.0'

?保存之后在終端輸入:

pod install

iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼,ios,swift,cocoapods,開發(fā)語言,xcode

?下載之后引入JSON解析包,寫入代碼,測(cè)試.

import UIKit
import CoreLocation
import Alamofire   //引入和風(fēng)API包
import SwiftyJSON   //引入解析JSON數(shù)據(jù)的包

class ViewController: UIViewController, CLLocationManagerDelegate {    //遵循CLLocationManagerDelegate協(xié)議
    //位置管理器
    let locationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        locationManager.requestWhenInUseAuthorization()    //請(qǐng)求當(dāng)用戶正在使用app的時(shí)候允許后臺(tái)得到用戶位置.只會(huì)彈出來一次
        locationManager.delegate = self    //位置管理器代理人是view controller對(duì)象.希望view controller能通過實(shí)現(xiàn)CLLocationManagerDelegate協(xié)議中的方法,獲取到當(dāng)前用戶位置信息
        locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers    //設(shè)置需要的位置精度(三公里誤差精度)
        locationManager.requestLocation()    //請(qǐng)求用戶位置
        
        
    }
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {  //requesLocation請(qǐng)求到了的話會(huì)執(zhí)行這個(gè)方法
        let lon = locations[0].coordinate.longitude   //精度.因?yàn)閘ocation可能實(shí)時(shí)變化(地圖app),所以是一個(gè)數(shù)組.我們只需要使用第一個(gè)獲取到的位置.
        let lat = locations[0].coordinate.latitude    //緯度
        //print(lon)
        //print(lat)
        AF.request("https://devapi.qweather.com/v7/weather/now?location=\(lon),\(lat)&key=a91848aaab484a3599a703b139dfe87b").responseJSON { response in
            if let data = response.value{
                let weatherJSON = JSON(data)
                print(weatherJSON)
            }
        }      //請(qǐng)求和風(fēng)API的網(wǎng)址,得到當(dāng)前位置的天氣
    }
    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {    //requesLocation請(qǐng)求失敗的話會(huì)執(zhí)行這個(gè)方法
        print(error)
    }
}

?啟動(dòng)運(yùn)行:

iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼,ios,swift,cocoapods,開發(fā)語言,xcode

?6.拿到天氣數(shù)據(jù)并展示在界面上

把溫度拖拽到ViewController中.

iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼,ios,swift,cocoapods,開發(fā)語言,xcode

?同理,將天氣圖標(biāo)和用戶當(dāng)前所在的城市也拖拽到代碼區(qū).

iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼,ios,swift,cocoapods,開發(fā)語言,xcode

?新建一個(gè)swift文件:

iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼,ios,swift,cocoapods,開發(fā)語言,xcode

Weather.swift:

import Foundation

class Weather{
    var temp = ""
    var icon = ""
    var city = ""
}

ViewController:

import UIKit
import CoreLocation
import Alamofire   //引入和風(fēng)API包
import SwiftyJSON   //引入解析JSON數(shù)據(jù)的包

class ViewController: UIViewController, CLLocationManagerDelegate {    //遵循CLLocationManagerDelegate協(xié)議
    @IBOutlet weak var tempLable: UILabel!
    
    @IBOutlet weak var iconImageView: UIImageView!
    
    @IBOutlet weak var cityLable: UILabel!
    
    //位置管理器
    let locationManager = CLLocationManager()
    //Weather.swift實(shí)例化
    let weather = Weather()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        locationManager.requestWhenInUseAuthorization()    //請(qǐng)求當(dāng)用戶正在使用app的時(shí)候允許后臺(tái)得到用戶位置.只會(huì)彈出來一次
        locationManager.delegate = self    //位置管理器代理人是view controller對(duì)象.希望view controller能通過實(shí)現(xiàn)CLLocationManagerDelegate協(xié)議中的方法,獲取到當(dāng)前用戶位置信息
        locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers    //設(shè)置需要的位置精度(三公里誤差精度)
        locationManager.requestLocation()    //請(qǐng)求用戶位置
        
        
    }
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {  //requesLocation請(qǐng)求到了的話會(huì)執(zhí)行這個(gè)方法
        let lon = locations[0].coordinate.longitude   //精度.因?yàn)閘ocation可能實(shí)時(shí)變化(地圖app),所以是一個(gè)數(shù)組.我們只需要使用第一個(gè)獲取到的位置.
        let lat = locations[0].coordinate.latitude    //緯度
        //print(lon)
        //print(lat)
        AF.request("https://devapi.qweather.com/v7/weather/now?location=\(lon),\(lat)&key=a91848aaab484a3599a703b139dfe87b").responseJSON { response in
            if let data = response.value{
                let weatherJSON = JSON(data)
                //print(weatherJSON["now"]["temp"])    //或weatherJSON["now", "temp"]
                //print(weatherJSON["refer"]["sources"][0])     //weatherJSON["refer", "sources", 0]
                
                //MVC結(jié)構(gòu)
                self.weather.temp = "\(weatherJSON["now"]["temp"].stringValue)?"
                self.weather.icon = weatherJSON["now"]["icon"].stringValue
                
                self.tempLable.text = self.weather.temp
                self.iconImageView.image = UIImage(named: self.weather.icon)
            }
        }      //請(qǐng)求和風(fēng)API的網(wǎng)址,得到當(dāng)前位置的天氣
    }
    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {    //requesLocation請(qǐng)求失敗的話會(huì)執(zhí)行這個(gè)方法
        print(error)
    }
}

?啟動(dòng)測(cè)試:

iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼,ios,swift,cocoapods,開發(fā)語言,xcode

?7.獲取用戶當(dāng)前所在的城市

ViewController:

import UIKit
import CoreLocation
import Alamofire   //引入和風(fēng)API包
import SwiftyJSON   //引入解析JSON數(shù)據(jù)的包

class ViewController: UIViewController, CLLocationManagerDelegate {    //遵循CLLocationManagerDelegate協(xié)議
    @IBOutlet weak var tempLable: UILabel!
    
    @IBOutlet weak var iconImageView: UIImageView!
    
    @IBOutlet weak var cityLable: UILabel!
    
    //位置管理器
    let locationManager = CLLocationManager()
    //Weather.swift實(shí)例化
    let weather = Weather()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        locationManager.requestWhenInUseAuthorization()    //請(qǐng)求當(dāng)用戶正在使用app的時(shí)候允許后臺(tái)得到用戶位置.只會(huì)彈出來一次
        locationManager.delegate = self    //位置管理器代理人是view controller對(duì)象.希望view controller能通過實(shí)現(xiàn)CLLocationManagerDelegate協(xié)議中的方法,獲取到當(dāng)前用戶位置信息
        locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers    //設(shè)置需要的位置精度(三公里誤差精度)
        locationManager.requestLocation()    //請(qǐng)求用戶位置
        
        
    }
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {  //requesLocation請(qǐng)求到了的話會(huì)執(zhí)行這個(gè)方法
        let lon = locations[0].coordinate.longitude   //精度.因?yàn)閘ocation可能實(shí)時(shí)變化(地圖app),所以是一個(gè)數(shù)組.我們只需要使用第一個(gè)獲取到的位置.
        let lat = locations[0].coordinate.latitude    //緯度
        //print(lon)
        //print(lat)
        AF.request("https://devapi.qweather.com/v7/weather/now?location=\(lon),\(lat)&key=a91848aaab484a3599a703b139dfe87b").responseJSON { response in
            if let data = response.value{
                let weatherJSON = JSON(data)
                //print(weatherJSON["now"]["temp"])    //或weatherJSON["now", "temp"]
                //print(weatherJSON["refer"]["sources"][0])     //weatherJSON["refer", "sources", 0]
                
                //MVC結(jié)構(gòu)
                self.weather.temp = "\(weatherJSON["now"]["temp"].stringValue)?"
                self.weather.icon = weatherJSON["now"]["icon"].stringValue
                
                self.tempLable.text = self.weather.temp
                self.iconImageView.image = UIImage(named: self.weather.icon)
                
                
            }
        }      //請(qǐng)求和風(fēng)API的網(wǎng)址,得到當(dāng)前位置的天氣
        
        AF.request("https://geoapi.qweather.com/v2/city/lookup?location=\(lon),\(lat)&key=a91848aaab484a3599a703b139dfe87b").responseJSON { response in
            if let data = response.value{
                let cityJSON = JSON(data)
                //處理數(shù)據(jù)
                self.weather.city = cityJSON["location", 0, "name"].stringValue
                //處理AI
                self.cityLable.text = self.weather.city
            }
        }
    }
    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {    //requesLocation請(qǐng)求失敗的話會(huì)執(zhí)行這個(gè)方法

? ? ? ??cityLable.text = "獲取用戶城市失敗"


    }


}

啟動(dòng)測(cè)試:

iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼,ios,swift,cocoapods,開發(fā)語言,xcode文章來源地址http://www.zghlxwxcb.cn/news/detail-697207.html

到了這里,關(guān)于iOS開發(fā)Swift-10-位置授權(quán), cocoapods,API,天氣獲取,城市獲取-和風(fēng)天氣App首頁代碼的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 免費(fèi)天氣類API接口集合,快速獲取天氣數(shù)據(jù)

    天氣類 歷史天氣預(yù)報(bào):可查詢國內(nèi)指定城市的歷史天氣預(yù)報(bào)數(shù)據(jù),最長可查詢至2018年1月1日。目前支持3400+國內(nèi)城市的歷史預(yù)報(bào)數(shù)據(jù)查詢,同時(shí)也支持國內(nèi)任意經(jīng)緯度查詢。 天氣預(yù)報(bào)查詢:查詢?nèi)珖约叭蚨鄠€(gè)城市的天氣,包含15天天氣預(yù)報(bào)查詢。 分鐘級(jí)降水預(yù)報(bào):可準(zhǔn)確

    2024年02月11日
    瀏覽(21)
  • 【微信小程序】使用和風(fēng)天氣接口api(全過程)——獲取天氣

    【微信小程序】使用和風(fēng)天氣接口api(全過程)——獲取天氣

    介紹 這里是小編成長之路的歷程,也是小編的學(xué)習(xí)之路。希望和各位大佬們一起成長! 以下為小編最喜歡的兩句話: 要有最樸素的生活和最遙遠(yuǎn)的夢(mèng)想,即使明天天寒地凍,山高水遠(yuǎn),路遠(yuǎn)馬亡。 一個(gè)人為什么要努力? 我見過最好的答案就是:因?yàn)槲蚁矚g的東西都很貴,

    2023年04月08日
    瀏覽(68)
  • CocoaPods 在iOS開發(fā)中養(yǎng)活了這么多項(xiàng)目,它到底是個(gè)啥?

    對(duì)于iOS開發(fā)者而言,CocoaPods并不陌生,通過pod相關(guān)的命令操作,就可以很方便的將項(xiàng)目中用到的三方依賴庫資源集成到項(xiàng)目環(huán)境中,大大的提升了開發(fā)的效率。CocoaPods作為iOS項(xiàng)目的包管理工具,它在命令行背后做了什么操作?而又是通過什么樣的方式將命令指令聲明出來供我

    2024年02月08日
    瀏覽(20)
  • STM32使用ESP8266模塊AT指令連接心知天氣API獲取天氣信息

    STM32使用ESP8266模塊AT指令連接心知天氣API獲取天氣信息

    由于之前使用STM32單片機(jī)來開發(fā)一些物聯(lián)網(wǎng)的小項(xiàng)目,接觸到了WIFI模塊ESP8266,所以寫下來記錄一下。 本文主要介紹的是STM32通過發(fā)送AT指令集來控制ESP8266 WIFI模塊連接WiFi并與心知天氣API建立TCP連接獲取天氣信息。 ESP8266我使用的是正點(diǎn)原子的ATK-ESP8266,已經(jīng)提前燒錄好AT指令集

    2023年04月08日
    瀏覽(26)
  • iOS開發(fā)Swift-函數(shù)

    ?(1)無參函數(shù) (2)多參函數(shù) (3)無返回值 (4)多重返回值 (5)可選元組返回類型(元組可以是nil) (6)隱式返回的函數(shù) 任一可以被寫成一行return的函數(shù),return(x) + for。 調(diào)用的時(shí)候: 方法名(for: 參數(shù)) (1)指定參數(shù)標(biāo)簽 (2)忽略參數(shù)標(biāo)簽 (3)默認(rèn)參數(shù)值 (4)可變參數(shù) 一個(gè)可變參數(shù)可接受0個(gè)或多

    2024年02月11日
    瀏覽(27)
  • iOS開發(fā)Swift-閉包

    將很長的閉包表達(dá)式作為最后一個(gè)參數(shù)傳遞給函數(shù),不用寫出他的參數(shù)標(biāo)簽。 嵌套函數(shù)可捕獲其外部函數(shù)所有參數(shù)、變量、常量。 當(dāng)一個(gè)閉包作為一個(gè)參數(shù)傳到一個(gè)函數(shù)中,但閉包在函數(shù)返回之后才被執(zhí)行,則稱閉包逃逸。 標(biāo)注@escaping,表示允許閉包逃逸。 ?包裝傳遞給函數(shù)

    2024年02月11日
    瀏覽(17)
  • iOS開發(fā)Swift-枚舉

    枚舉:一組相關(guān)的值定義了一個(gè)共同的類型,使你可以在代碼中以類型安全的方式來使用這些值。 原始值:定義枚舉時(shí)被預(yù)先填充的值。 (1)整數(shù)為原始值時(shí),隱式賦值遞增1。未設(shè)置原始值時(shí),默認(rèn)為0,之后遞增1. (2)字符串為原始值,隱式賦值為枚舉成員的名稱。

    2024年02月11日
    瀏覽(28)
  • 細(xì)數(shù)N個(gè)獲取天氣信息的免費(fèi) API ,附超多免費(fèi)可用API 推薦(三)

    市面上有 N 多個(gè)查詢天氣信息的軟件、小程序以及網(wǎng)頁入口,基本都是通過調(diào)用天氣查詢 API 去實(shí)現(xiàn)的。 今天整理了一下多種場(chǎng)景的天氣預(yù)報(bào)API 接口分享給大家,有需要趕緊收藏起來。 天氣預(yù)報(bào)查詢支持全國以及全球多個(gè)城市的天氣查詢,包含國內(nèi)3400+個(gè)城市以及國際4萬個(gè)

    2024年02月02日
    瀏覽(18)
  • 【微信小程序】免費(fèi)的高德地圖api——獲取天氣(全過程)

    【微信小程序】免費(fèi)的高德地圖api——獲取天氣(全過程)

    介紹 這里是小編成長之路的歷程,也是小編的學(xué)習(xí)之路。希望和各位大佬們一起成長! 以下為小編最喜歡的兩句話: 要有最樸素的生活和最遙遠(yuǎn)的夢(mèng)想,即使明天天寒地凍,山高水遠(yuǎn),路遠(yuǎn)馬亡。 一個(gè)人為什么要努力? 我見過最好的答案就是:因?yàn)槲蚁矚g的東西都很貴,

    2024年02月02日
    瀏覽(102)
  • Flutter開發(fā)- iOS 問題CocoaPods not installed or not in valid state

    Flutter開發(fā)- iOS 問題CocoaPods not installed or not in valid state

    解決問題方案: 1、先檢查本機(jī)CocoaPods是否安裝,通過gem list 查看是否安裝 ?打開終端,執(zhí)行g(shù)em list,出現(xiàn)圖中的數(shù)據(jù)即為已安裝。未安裝看第4 步 2、已經(jīng)安裝了CocoaPods,還出現(xiàn)了圖中的提示,你可能已經(jīng)猜到是 Android studio 出現(xiàn)了問題,但是常規(guī)的關(guān)閉再打開的方式無法解決

    2024年02月10日
    瀏覽(22)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包