1. 圖標與啓動頁
a) 先來一個原始文件最好是正方形的 1024 * 1024 像素以上
b) 調查一下需要的尺寸 參照 Assets.xcassets/AppIcon 要求(使用PS軟件)
c) 啓動頁面 New iOS Launch Image 尺寸相關
d) 選擇項目的App Icons and Launch Images , 清除 Launch Screen File , 選擇 Launch Image Source , Requires full screen 勾選
e) 選擇LaunchScreen.storyboard , Use as Launch Screen 取消勾選(完成後需要刪除App重新安裝後才能看到效果)
2. 全球本地化
a) 名稱本地化
* 添加語言: 選中Project , Localizations , 添加語言
* 新建文件: 類型爲strings, 名稱爲InfoPlist
* 添加內容: CFBundleDisplayName = ""; 注意分號
b) 內容本地化
* 添加語言: 同上
* 新建語言: 類型爲strings, 名稱爲Localizable
* 添加內容: "xxx" = "xxx"; 注意分號
3. 登錄界面
a) 去掉不必要的提示信息: Product -> Scheme -> Edit Scheme -> Run -> Environment Variables -> OS_ACTIVITY_MODE Value:disable
b) Api 設置 : Info.plist -> App Transport Security Setting -> Allow Arbitrary Loads -> Yes
c) 點擊空白處隱藏鍵盤
//點擊空白處隱藏鍵盤
override func touchesBegan(_ touches:Set<UITouch>, with event:UIEvent?) {
view.endEditing(true)
}
d) 文字加載
//根據語言加載文字內容
func languageLoad() {
btnLogin.setTitle(NSLocalizedString("btn_main_login", comment: "btn_main_login"), for: .normal)
txtLoginID.placeholder =NSLocalizedString("lab_main_id", comment:"txtLoginID")
txtLoginPW.placeholder =NSLocalizedString("lab_main_pw", comment:"txtLoginPW")
}
e) 獲取天氣數據 ( 獲取數據的api 地址 UrlStringCollection.weatherUrl ,自己拼接)
//獲取天氣數據
func weatherLoad() {
let config =URLSessionConfiguration.default
config.timeoutIntervalForRequest =10
let session = URLSession(configuration: config)
let task = session.dataTask(with:UrlStringCollection.weatherUrl!) { (data,_,error)in
if error == nil {
let json = (try?JSONSerialization.jsonObject(with: data!, options: .mutableContainers))as?NSDictionary
let weather = (json?.value(forKey:"result")as?NSDictionary).map {
WeatherItem(WeatherDate: ($0["days"]as?String)?.appending($0["week"]as!String)
,Weather: $0["weather"]as?String
,WeatherImage: $0["weather_icon"]as?String
,WeatherTemperature: $0["temperature"]as?String)
}
DispatchQueue.main.async {
self.weatherData = weather
}
}
}
task.resume()
}
f) 登錄後跳轉頁面 (登錄的api地址 自己拼接)- 後續更新alamofire 方式
func accountLogin(accountId:String,accountPw:String) {
UrlStringCollection.accountId = accountId
UrlStringCollection.accountPw = accountPw
let url =URL(string:UrlStringCollection.accountIsExistUrl)
let session = URLSession.shared
let request = URLRequest(url: url!)
let task = session.dataTask(with: request) { (data,response,error)in
let json = try? JSON(data:data!)
let result = JSON(json!)["Table"].count
DispatchQueue.main.async {
if result > 0 {
self.performSegue(withIdentifier:"login_in", sender: self)
} else {
//這邊彈出錯誤提示 ,對於網絡連接錯誤可以使用 error == nil 來判定
let alertController = UIAlertController(title: "Error", message:"ID Error", preferredStyle: .alert)
let alertAction = UIAlertAction(title: "確定", style: .default, handler:nil)
alertController.addAction(alertAction)
self.present(alertController, animated:true, completion: nil)
}
}
}
task.resume()
}