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()
}