NFCMessageVC.swift 5.17 KB
//
//  NFCMessageVC.swift
//  Twear
//
//  Created by yangbin on 2022/2/12.
//

import UIKit
import MBProgressHUD

class NFCMessageVC: UIViewController {
    
    @IBOutlet weak var payloadTF: UITextField!
    @IBOutlet weak var typeTF: UITextField!
    @IBOutlet weak var identifierTF: UITextField!
    @IBOutlet weak var formatBtn: UIButton!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = LocString("生成空白卡")
        // Do any additional setup after loading the view.
        let doneButton = UIButton(frame: CGRect(x: 0, y: 0, width: 40, height: 28))
        doneButton.setTitle(LocString("完成"), for: .normal)
        doneButton.titleLabel?.font = RegularFont(14)
        doneButton.setTitleColor(TintColor, for: .normal)
        doneButton.addTarget(self, action: #selector(save), for: .touchUpInside)
        navigationItem.rightBarButtonItem =  UIBarButtonItem(customView: doneButton)
    }
    @objc private func save() {
        if payloadTF.text == "" {
            MBProgressHUD.showh(LocString("请输入内容"))
            return
        }
        if #available(iOS 13.0, *) {
            let nfc = NFCModel()
            nfc.identifier = identifierTF.text ?? ""
            nfc.payload = payloadTF.text ?? ""
            nfc.type = typeTF.text ?? ""
            nfc.format = formatBtn.titleLabel?.text ?? ""
            
            let user = UserInfo
            user.nfc.append(nfc)
            AdminHelper.shared.updateUser(user)
            //                    if device.nfc.count == 1 {
            let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Setting", identifier: "NFCViewController") as! NFCViewController
            vc.nfcList = user.nfc
            self.navigationController?.pushViewController(vc, animated: true)
            //                    } else {
            //                        if (self.navigationController?.viewControllers.count)! >= 2 {
            //                            guard let vc = self.navigationController?.viewControllers[1] else { return
            //                            }
            //                            self.navigationController?.popToViewController(vc, animated: true)
            //                        }
            //                    }
            
            
            print(nfc.identifier)
            print(nfc.payload)
            print(nfc.type)
            print(nfc.format)
        }
        
    }
    
    @IBAction func selectFormat(_ sender: Any) {
        let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
        
        
        let archiveAction1 = UIAlertAction(title: "nfcWellKnown", style: .default) { action in
            self.formatBtn.setTitle("nfcWellKnown", for: .normal)
        }
        archiveAction1.setValue(UIColor.black, forKey: "titleTextColor")
        let archiveAction2 = UIAlertAction(title: "empty", style: .default) { action in
            self.formatBtn.setTitle("empty", for: .normal)
        }
        archiveAction2.setValue(UIColor.black, forKey: "titleTextColor")
        let archiveAction3 = UIAlertAction(title: "media", style: .default) { action in
            self.formatBtn.setTitle("media", for: .normal)
        }
        archiveAction3.setValue(UIColor.black, forKey: "titleTextColor")
        let archiveAction4 = UIAlertAction(title: "absoluteURI", style: .default) { action in
            self.formatBtn.setTitle("absoluteURI", for: .normal)
        }
        archiveAction4.setValue(UIColor.black, forKey: "titleTextColor")
        let archiveAction5 = UIAlertAction(title: "nfcExternal", style: .default) { action in
            self.formatBtn.setTitle("nfcExternal", for: .normal)
        }
        archiveAction5.setValue(UIColor.black, forKey: "titleTextColor")
        let archiveAction6 = UIAlertAction(title: "unknown", style: .default) { action in
            self.formatBtn.setTitle("unknown", for: .normal)
        }
        archiveAction6.setValue(UIColor.black, forKey: "titleTextColor")
        let archiveAction7 = UIAlertAction(title: "unchanged", style: .default) { action in
            self.formatBtn.setTitle("unchanged", for: .normal)
        }
        archiveAction7.setValue(UIColor.black, forKey: "titleTextColor")
        let archiveAction8 = UIAlertAction(title: "unknown", style: .default) { action in
            self.formatBtn.setTitle("unknown", for: .normal)
        }
        archiveAction8.setValue(UIColor.black, forKey: "titleTextColor")
        alert.addAction(archiveAction1)
        alert.addAction(archiveAction2)
        alert.addAction(archiveAction3)
        alert.addAction(archiveAction4)
        alert.addAction(archiveAction5)
        alert.addAction(archiveAction6)
        alert.addAction(archiveAction7)
        alert.addAction(archiveAction8)
        present(alert, animated: true, completion: nil)
    }
    
    /*
     // 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.
     }
     */
    
}