66e7e76d
yangbin
NFC
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
//
// 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.
}
*/
}
|