You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
259 lines
11 KiB
259 lines
11 KiB
1 year ago
|
//
|
||
1 year ago
|
// UpdataQRCodeImgViewControllers.swift
|
||
1 year ago
|
// FireBoltt
|
||
1 year ago
|
//
|
||
|
// Created by ecell on 2022/9/23.
|
||
|
// Copyright © 2022 Sheldon. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import UIKit
|
||
|
import AVFoundation
|
||
|
|
||
1 year ago
|
class UpdataQRCodeImgViewControllers: ViewController {
|
||
1 year ago
|
|
||
|
var titleStr: String = ""
|
||
|
var paytype: Int = 1
|
||
|
let codeButton = UIButton()
|
||
|
var seleceImg = UIImage()
|
||
|
var viewTypeStr: String = ""
|
||
|
|
||
|
|
||
|
override func viewDidLoad() {
|
||
|
super.viewDidLoad()
|
||
|
self.monitor()
|
||
|
self.view.backgroundColor = UIColor.white
|
||
|
// Do any additional setup after loading the view.
|
||
|
|
||
|
codeButton.backgroundColor = UIColor.white
|
||
1 year ago
|
codeButton.setImage(R.image.fb_Qrcode_bg_icon(), for: .normal)
|
||
1 year ago
|
codeButton.layer.cornerRadius = 5.0
|
||
|
//button.layer.masksToBounds = true
|
||
|
codeButton.layer.shadowColor = UIColor(red: 255/255, green: 192/255, blue: 125/255, alpha: 0.28).cgColor
|
||
|
codeButton.layer.shadowRadius = 8
|
||
|
codeButton.layer.shadowOffset = CGSize(width: 0, height: 2)
|
||
|
codeButton.layer.shadowOpacity = 1
|
||
|
codeButton.layer.backgroundColor = UIColor.white.cgColor
|
||
|
codeButton.addTarget(self, action: #selector(selectImg), for: .touchUpInside)
|
||
|
self.view.addSubview(codeButton)
|
||
|
codeButton.snp.makeConstraints { (make) in
|
||
|
make.top.equalTo(self.view).offset(20)
|
||
|
make.centerX.equalTo(self.view)
|
||
|
make.height.width.equalTo(kScaleWidth(180))
|
||
|
//make.width.equalTo(kScaleWidth(160))
|
||
|
}
|
||
|
|
||
|
guard let objData = UserDefaults.standard.data(forKey: String(format: "QRCPDE%d%@", self.paytype,self.viewTypeStr)) else { return }
|
||
|
let decoded = try! PropertyListDecoder().decode(Data.self, from: objData)
|
||
|
let image = UIImage(data: decoded)
|
||
|
if (image != nil) {
|
||
|
self.codeButton.setImage(image, for: .normal)
|
||
|
seleceImg = image!
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
override func bindViewModel() {
|
||
1 year ago
|
guard let viewModel = viewModel as? UpdataQRCodeImgViewModels else { return }
|
||
1 year ago
|
print("%@",viewModel.titleName)
|
||
|
self.paytype = viewModel.payType
|
||
|
self.titleStr = viewModel.titleName
|
||
|
self.viewTypeStr = viewModel.viewType
|
||
|
self.makesUI()
|
||
|
}
|
||
|
|
||
|
func makesUI() {
|
||
|
let tiLabel:UILabel = UILabel()
|
||
|
tiLabel.textColor = kRGBA(102, 102, 102, 1)
|
||
|
tiLabel.font = SystemRegularFont(15)
|
||
|
tiLabel.numberOfLines = 0
|
||
1 year ago
|
tiLabel.text = String(format: "%@%@%@%@%@%@%@\n\n%@", MultiLanguageKey_FB.bindingSteps_1FB.localized,
|
||
1 year ago
|
self.titleStr.localized,
|
||
1 year ago
|
MultiLanguageKey_FB.bindingSteps_2FB.localized,
|
||
1 year ago
|
self.titleStr.localized,
|
||
1 year ago
|
MultiLanguageKey_FB.bindingSteps_3FB.localized,
|
||
1 year ago
|
self.titleStr.localized,
|
||
1 year ago
|
MultiLanguageKey_FB.bindingSteps_4FB.localized
|
||
|
,MultiLanguageKey_FB.attentionFB.localized)
|
||
1 year ago
|
self.view.addSubview(tiLabel);
|
||
|
tiLabel.snp.makeConstraints { (make) in
|
||
|
make.top.equalTo(self.view).offset(45+kScaleWidth(180))
|
||
|
make.left.equalTo(self.view).offset(15)
|
||
|
make.right.equalTo(self.view.snp.right).inset(15)
|
||
|
}
|
||
|
|
||
|
|
||
|
let button = UIButton()
|
||
1 year ago
|
button.gradient(colors: [kHexColor(0x59AAFF), kHexColor(0x2B75FF)], startPoint: CGPoint(x: 0, y: 0.5), endPoint: CGPoint(x: 1, y: 0.5), locations: [0, 1], autoLaoutFrame: CGRect(x: 0, y: 0, width: self.view.frame.size.width-60, height: kScaleWidth(44)))
|
||
1 year ago
|
button.layer.cornerRadius = kScaleWidth(22)
|
||
|
button.layer.masksToBounds = true
|
||
1 year ago
|
button.setTitle(MultiLanguageKey_FB.bindingQrCodeFB.localized, for: .normal)//设置按钮显示的文字
|
||
1 year ago
|
button.setTitleColor(UIColor.white, for: .normal)
|
||
|
button.titleLabel?.font = SystemRegularFont(15)
|
||
|
self.view.addSubview(button);
|
||
|
button.snp.makeConstraints { make in
|
||
|
make.bottom.equalTo(self.view.bottom).inset(30)
|
||
|
make.left.equalTo(self.view).offset(30)
|
||
|
make.right.equalTo(self.view.snp.right).inset(30)
|
||
|
make.height.equalTo(kScaleWidth(44))
|
||
|
}
|
||
|
button.addTarget(self, action: #selector(bindingTouch), for: .touchUpInside)
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
@objc func bindingTouch(){
|
||
|
print("绑定")
|
||
|
let str: String = String(stringLiteral:self.recognitionQRCode(qrCodeImage: self.seleceImg)!)
|
||
|
if (str.lengthOfBytes(using: String.Encoding.utf16) > 0) {
|
||
|
SVProgressHUD.show()
|
||
|
BluetoothService.shared.qrCodePushWithBleCmdType(payImgStr: self.seleceImg, type: self.paytype)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// 选择图片
|
||
|
@objc func selectImg(){
|
||
1 year ago
|
self.setAvatorFB()
|
||
1 year ago
|
}
|
||
|
|
||
|
/* * @param qrCodeImage 二维码的图片
|
||
|
* @return 结果的数组 */
|
||
|
func recognitionQRCode(qrCodeImage: UIImage) -> String? {
|
||
|
let detector = CIDetector(ofType: CIDetectorTypeQRCode, context: nil, options: nil)
|
||
|
guard let ciImage = CIImage(image: qrCodeImage) else { return nil }
|
||
|
guard let features = detector?.features(in: ciImage) else { return nil }
|
||
|
var codeStr = String()
|
||
|
for feature in features {
|
||
|
codeStr = (feature as! CIQRCodeFeature).messageString!
|
||
|
}
|
||
|
|
||
|
return codeStr
|
||
|
}
|
||
|
|
||
1 year ago
|
func fbjudgeQRCode(qrCodeImage: UIImage){
|
||
1 year ago
|
let str: String = String(stringLiteral:self.recognitionQRCode(qrCodeImage: qrCodeImage)!)
|
||
|
if (str.lengthOfBytes(using: String.Encoding.utf16) > 0) {
|
||
|
self.seleceImg = qrCodeImage
|
||
|
self.codeButton.setImage(qrCodeImage, for: .normal)
|
||
|
}
|
||
|
else
|
||
|
{
|
||
1 year ago
|
SVProgressHUD.showError(withStatus: MultiLanguageKey_FB.invalidQrCodeFB.localized)
|
||
1 year ago
|
}
|
||
|
}
|
||
|
|
||
|
func monitor() {
|
||
|
/// 指令成功失败监听
|
||
|
Observable.of(kNotificationCenter.rx.notification(Notification.Name(rawValue: CmdSuccess)),
|
||
|
kNotificationCenter.rx.notification(Notification.Name(rawValue: CmdTimeout)))
|
||
|
.merge()
|
||
|
.subscribe(onNext: { [weak self] notification in
|
||
1 year ago
|
guard let `self` = self, let cmd = notification.object as? BleCMD_FireBoltt else { return }
|
||
1 year ago
|
let isSuccess = notification.name.rawValue == CmdSuccess
|
||
|
switch cmd {
|
||
|
case .qrCodePush:
|
||
|
if isSuccess {
|
||
1 year ago
|
SVProgressHUD.showSuccess(withStatus: MultiLanguageKey_FB.syncDataSucceedFB.localized)
|
||
1 year ago
|
//self.navigationController?.popViewController(animated: true)
|
||
|
guard let data = self.seleceImg.jpegData(compressionQuality: 0.5) else { return }
|
||
|
let encoded = try! PropertyListEncoder().encode(data)
|
||
|
UserDefaults.standard.set(encoded, forKey: String(format: "QRCPDE%d%@", self.paytype,self.viewTypeStr))
|
||
|
return
|
||
|
}
|
||
1 year ago
|
SVProgressHUD.showSuccess(withStatus: MultiLanguageKey_FB.setFailFB.localized)
|
||
1 year ago
|
default: break
|
||
|
}
|
||
|
})
|
||
|
.disposed(by: rx.disposeBag)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
1 year ago
|
extension UpdataQRCodeImgViewControllers {
|
||
1 year ago
|
func setAvatorFB() {
|
||
1 year ago
|
let alertC = UIAlertController.init(title: nil, message: nil, preferredStyle: .actionSheet)
|
||
1 year ago
|
alertC.addAction(UIAlertAction.init(title: MultiLanguageKey_FB.cancelFB.localized, style: UIAlertAction.Style.cancel, handler: nil))
|
||
|
let camera = UIAlertAction.init(title: MultiLanguageKey_FB.cameraFB.localized, style: UIAlertAction.Style.default, handler: {[weak self] (_) in
|
||
1 year ago
|
guard let `self` = self else { return }
|
||
|
|
||
|
let authStatus = AVCaptureDevice.authorizationStatus(for: AVMediaType.video)
|
||
|
if authStatus == .denied || authStatus == .restricted {
|
||
1 year ago
|
let alertVC = UIAlertController.init(title: MultiLanguageKey_FB.tipFB.localized, message: MultiLanguageKey_FB.carmaPowerFB.localized, preferredStyle: .alert)
|
||
|
let goToAction = UIAlertAction.init(title: MultiLanguageKey_FB.gotoFB.localized, style: .default) { (action) in
|
||
1 year ago
|
if let url = URL(string: UIApplication.openSettingsURLString) {
|
||
|
if UIApplication.shared.canOpenURL(url) {
|
||
|
UIApplication.shared.openURL(url)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
1 year ago
|
let cancelAction = UIAlertAction(title: MultiLanguageKey_FB.cancelFB.localized, style: .cancel, handler: nil)
|
||
1 year ago
|
alertVC.addAction(goToAction)
|
||
|
alertVC.addAction(cancelAction)
|
||
|
self.present(alertVC, animated: true, completion: nil)
|
||
|
return
|
||
|
}
|
||
|
self.cameraAction()
|
||
|
})
|
||
|
|
||
1 year ago
|
let gallery = UIAlertAction.init(title: MultiLanguageKey_FB.photoSelectFB.localized, style: UIAlertAction.Style.default, handler: { [weak self](_) in
|
||
1 year ago
|
guard let `self` = self else { return }
|
||
|
self.galleryAction()
|
||
|
})
|
||
|
alertC.addAction(camera)
|
||
|
alertC.addAction(gallery)
|
||
|
self.present(alertC, animated: true, completion: nil)
|
||
|
}
|
||
|
|
||
|
func cameraAction() {
|
||
|
UIImagePickerController.rx.createWithParent(self, animated: true) { (picker) in
|
||
|
picker.allowsEditing = true
|
||
|
picker.sourceType = .camera
|
||
|
}
|
||
|
.flatMap {
|
||
|
$0.rx.didFinishPickingMediaWithInfo
|
||
|
}
|
||
|
.take(1)
|
||
|
.map { info in
|
||
|
return info[UIImagePickerController.InfoKey.editedImage.rawValue] as? UIImage
|
||
|
}
|
||
|
.subscribe(onNext: { [weak self](chooseImg) in
|
||
|
guard let `self` = self, let chooseImg = chooseImg else { return }
|
||
1 year ago
|
self.fbjudgeQRCode(qrCodeImage: chooseImg)
|
||
1 year ago
|
})
|
||
|
.disposed(by: rx.disposeBag)
|
||
|
}
|
||
|
|
||
|
func galleryAction() {
|
||
|
UIImagePickerController.rx.createWithParent(self, animated: true) { (picker) in
|
||
|
picker.allowsEditing = true
|
||
|
picker.sourceType = .photoLibrary
|
||
|
}
|
||
|
.flatMap {
|
||
|
$0.rx.didFinishPickingMediaWithInfo
|
||
|
}
|
||
|
.take(1)
|
||
|
.map { info in
|
||
|
return info[UIImagePickerController.InfoKey.editedImage.rawValue] as? UIImage
|
||
|
}
|
||
|
.subscribe(onNext: { [weak self](chooseImg) in
|
||
|
guard let `self` = self, let chooseImg = chooseImg else { return }
|
||
1 year ago
|
self.fbjudgeQRCode(qrCodeImage: chooseImg)
|
||
1 year ago
|
})
|
||
|
.disposed(by: rx.disposeBag)
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
/*
|
||
|
// MARK: - Navigation
|
||
|
|
||
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
||
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
||
|
// Get the new view controller using segue.destination.
|
||
|
// Pass the selected object to the new view controller.
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
|