Commit e2d70e4a authored by 刘俊宏's avatar 刘俊宏

修正登录bug+添加蓝牙连接模块

parent 56be3208
......@@ -12,5 +12,6 @@
#import "MJRefresh.h"
#import "WYHead.h"
#import "FSCalendar.h"
#import "BabyBluetooth.h"
#endif /* Bridge_Header_h */
......@@ -47,7 +47,6 @@ let NavCGRect = CGRect(x: 0, y: 0, width: Int(UIScreen.main.bounds.size.width),
let LoopHeight = UIScreen.main.bounds.size.width / 1.25
let UserToken = UserDefaults.standard.value(forKey: "user_token")
func IsOldIos() ->Bool{
......
......@@ -123,10 +123,12 @@ extension NetworkRequest {
HUD.flash(.label(json["message"].stringValue), delay: 1.5)
failture(DogError.DataInvalidError)
}else if json["code"].intValue == 10 {
NotificationCenter.default.post(name: Notification.Name(rawValue: "logout"), object: nil)
HUD.flash(.label(json["message"].stringValue), delay: 1.5)
failture(DogError.DataInvalidError)
delay(1.5) {
UserDefaults.standard.removeObject(forKey: "user_token")
NotificationCenter.default.post(name: Notification.Name(rawValue: "logout"), object: nil)
}
}else if json["code"].intValue == 11 {
HUD.flash(.label(json["message"].stringValue), delay: 1.5)
failture(DogError.DataInvalidError)
......
......@@ -61,17 +61,21 @@
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>我们需要通过您同意使用蓝牙,才能获取相关数据</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>我们需要通过您同意使用蓝牙,才能获取相关数据</string>
<key>NSCameraUsageDescription</key>
<string>我们需要通过您同意使用相机,才能获取回收柜的二维码相关数据</string>
<string>我们需要通过您同意使用相机,才能获取相关数据</string>
<key>NSContactsUsageDescription</key>
<string>我们需要通过您同意使用通讯录,才能访问您的好友列表</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>我们需要通过您同意获取地理位置,查询周边回收柜的相关数据</string>
<string>我们需要通过您同意获取地理位置,查询周边的相关数据</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>我们需要通过您同意获取地理位置,查询周边回收柜的相关数据</string>
<string>我们需要通过您同意获取地理位置,查询周边的相关数据</string>
<key>NSMicrophoneUsageDescription</key>
<string>我们需要通过您同意使用麦克风,才能与你进行语音交流</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>我们需要通过您同意使用相册,才能修改头像</string>
<string>我们需要通过您同意使用相册,才能修改图片</string>
</dict>
</plist>
......@@ -18,6 +18,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate, UITabBarControllerDeleg
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
sceneC = scene
let UserToken = UserDefaults.standard.value(forKey: "user_token")
if UserToken == nil {
addLoginVc(isAgain: false)
}else{
......
......@@ -20,6 +20,8 @@ class PersonCenterViewController: BaseViewController,UITableViewDelegate,UITable
let listArray = ["格利支付","蓝牙打印设置","权限设置"]
//MARK:--加载数据
func loadData(){
let UserToken = UserDefaults.standard.value(forKey: "user_token")
adminInfo(["user_token":UserToken as Any], success: { (data) in
self.dataModel = (data as! AdminInfoModel)
self.iconImg.kf.setImage(with: URL(string: SERVERCE_HOST + (self.dataModel?.data?.shop_img)!))
......
......@@ -58,6 +58,8 @@ class ChangePassViewController: BaseViewController {
oldPassTF.isSecureTextEntry = !oldPBtn.isSelected
}
@IBAction func submitAction(_ sender: Any) {
let UserToken = UserDefaults.standard.value(forKey: "user_token")
changePwd(["user_token":UserToken as Any,"pwd":oldPassTF.text as Any,"new_pwd":newPassTF.text as Any], success: { (data) in
HUD.flash(.labeledSubSuccess(subtitle: "修改成功"),delay: 1.5)
delay(1.5) {
......
......@@ -118,6 +118,8 @@ class GoodsManageListVC: BaseViewController, UICollectionViewDelegate, UICollect
page = pageNum
}
getSortData ()
let UserToken = UserDefaults.standard.value(forKey: "user_token")
goodsList(["user_token":UserToken as Any,"keyword":keyword,"goods_type":goodsType,"sort":sort,"is_show":isShow,"page":page], success: { (data) in
let dataM = data as! GoodsListModel
if self.isSearch {
......@@ -159,6 +161,8 @@ class GoodsManageListVC: BaseViewController, UICollectionViewDelegate, UICollect
page = pageNum
}
getSortData ()
let UserToken = UserDefaults.standard.value(forKey: "user_token")
goodsList(["user_token":UserToken as Any,"keyword":keyword,"goods_type":goodsType,"sort":sort,"is_show":isShow,"page":page], success: { (data) in
let dataM = data as! GoodsListModel
if (dataM.data?.goods_res!.count)! > 0 {
......
......@@ -24,6 +24,8 @@ class ShopInfoViewController: BaseViewController {
}
//MARK:--加载数据
func loadData(){
let UserToken = UserDefaults.standard.value(forKey: "user_token")
shopInfo(["user_token":UserToken as Any], success: { (data) in
self.dataModel = (data as! ShopInfoModel)
self.shopImgV.kf.setImage(with: URL(string: SERVERCE_HOST + (self.dataModel?.data?.shop_img)!))
......
......@@ -24,6 +24,8 @@ class PayViewController: BaseViewController {
navbar.title = "支付账号"
self.view.addSubview(navbar)
let UserToken = UserDefaults.standard.value(forKey: "user_token")
geliPayInfo(["user_token":UserToken as Any], success: { (data) in
let dataM = data as! GeliPayInfoModel
if dataM.data?.status == 3 {
......
......@@ -96,7 +96,7 @@ class LoginViewController: BaseViewController, CodeViewDelegate,GeliAlertViewDel
login(["user_name":phoneTF.text as Any,"pwd":passTF.text as Any], success: { (data) in
let dataM = data as! LoginModel
UserDefaults.standard.set(dataM.data?.user_token, forKey: "user_token")
// UserDefaults.standard.synchronize()
UserDefaults.standard.synchronize()
self.loginBtn.isLoading = false
self.delegate?.successLogin()
}) { (error) in
......
......@@ -7,13 +7,17 @@
//
import UIKit
import Dollar
class BluetoothConnectViewController: BaseViewController,UITableViewDelegate,UITableViewDataSource {
@IBOutlet weak var bottomView: UIView!
@IBOutlet weak var tableView: UITableView!
let baby = BabyBluetooth.share()
var peripheralDataArray : Array<CBPeripheral> = []
var selectDataArray : Array<CBPeripheral> = []
override func viewDidLoad() {
super.viewDidLoad()
navbar.title = "蓝牙打印设置"
......@@ -28,22 +32,80 @@ class BluetoothConnectViewController: BaseViewController,UITableViewDelegate,UIT
}
tableView?.register(UINib(nibName: "BlueToothCell", bundle: nil), forCellReuseIdentifier: "BlueTooth")
baby?.setBlockOnDiscoverToPeripherals({ (mangan, peripheral, adv, RSSI) in
})
baby?.setFilterOnDiscoverPeripherals({ (periName, adv, RSSI) -> Bool in
if periName != nil {
print("是否需要过滤\(periName)")
return true
}
return false
})
baby?.setBlockOnDiscoverToPeripherals({ (central, peripheral, adv, RSSI) in
print("搜索到的\(peripheral?.name)")
if !self.peripheralDataArray.contains(peripheral!){
self.peripheralDataArray.insert(peripheral!, at: 0)
self.tableView.reloadData()
}
})
baby?.scanForPeripherals()
baby?.begin()
//尝试链接
baby?.setBlockOnConnected({ (central, peripheral) in
print("设备\(peripheral?.name)连接成功")
self.selectDataArray.removeAll()
if self.peripheralDataArray.contains(peripheral!){
Dollar.remove(self.peripheralDataArray, value: peripheral)
}
self.selectDataArray.insert(peripheral!, at: 0)
self.tableView.reloadData()
})
baby?.setBlockOnCancelAllPeripheralsConnectionBlock({ (cetral) in
print("断开连接2223333")
let currPeripheral:CBPeripheral = self.selectDataArray[0]
self.peripheralDataArray.insert(currPeripheral, at: 0)
self.selectDataArray.removeAll()
self.tableView.reloadData()
})
}
//MARK: -方法
@IBAction func searchAction(_ sender: Any) {
print("搜索")
baby?.scanForPeripherals()
baby?.begin()
}
//MARK: -Cell delegate
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 0 {
print("准备取消所有连接11")
self.baby?.cancelAllPeripheralsConnection()
}else{
let currPeripheral:CBPeripheral = self.peripheralDataArray[indexPath.row]
print("准备连接的设备:\(currPeripheral.name)")
self.baby?.having(currPeripheral)?.and()?.channel("peripheralView")?.then()?.connectToPeripherals()?.begin()
}
}
func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0{
return 1
return self.selectDataArray.count
}
return 10
return self.peripheralDataArray.count
}
//header
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
......@@ -101,9 +163,18 @@ class BluetoothConnectViewController: BaseViewController,UITableViewDelegate,UIT
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "BlueTooth") as! BlueToothCell
if indexPath.section != 0 {
if indexPath.section == 0 {
let currPeripheral:CBPeripheral = self.selectDataArray[indexPath.row]
cell.contentLbl.text = currPeripheral.name
cell.statusIcon.isHidden = false
}else{
cell.statusIcon.isHidden = true
let currPeripheral:CBPeripheral = self.peripheralDataArray[indexPath.row]
cell.contentLbl.text = currPeripheral.name
}
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment