Skip to content

Commit 9832311

Browse files
author
zhaoyongqiang
committed
修改数据保存方式
1 parent fb0c4b6 commit 9832311

4 files changed

Lines changed: 21 additions & 6 deletions

File tree

iOS/APIExample/Common/GlobalSettings.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,21 @@ class GlobalSettings {
7070
func getSetting(key:String) -> SettingItem? {
7171
return settings[key]
7272
}
73+
74+
func setValue(key: String, value: Any) {
75+
UserDefaults.standard.set(value, forKey: key)
76+
UserDefaults.standard.synchronize()
77+
}
78+
func string(for key: String) -> String? {
79+
UserDefaults.standard.string(forKey: key)
80+
}
81+
func double(for key: String) -> Double {
82+
UserDefaults.standard.double(forKey: key)
83+
}
84+
func float(for key: String) -> Float {
85+
UserDefaults.standard.float(forKey: key)
86+
}
87+
func integer(for key: String) -> Int {
88+
UserDefaults.standard.integer(forKey: key)
89+
}
7390
}

iOS/APIExample/Examples/Advanced/LocalAccess/LocalAccess.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ class LocalAccessEntry : UIViewController
3434
}
3535
@IBAction func onLocalAccessTextFieldValueChange(_ sender: UITextField) {
3636
LogUtils.log(message: "value == \(sender.text ?? "")", level: .info)
37-
UserDefaults.standard.set(sender.text, forKey: "private")
38-
UserDefaults.standard.synchronize()
37+
GlobalSettings.shared.setValue(key: "private", value: sender.text)
3938
}
4039
}
4140

@@ -70,7 +69,7 @@ class LocalAccessMain: BaseViewController {
7069
agoraKit = AgoraRtcEngineKit.sharedEngine(with: config, delegate: self)
7170

7271
// setup accessPointConfig
73-
if let ip = UserDefaults.standard.string(forKey: "private") {
72+
if let ip = GlobalSettings.shared.string(for: "private") {
7473
let params = ["rtc.new_vos": false, "che.new_vos": false, "che.video.receiver_check_ref": false]
7574
let paramsString = Util.dicValueString(params) ?? ""
7675
agoraKit.setParameters(paramsString)

iOS/APIExample/Examples/Basic/JoinChannelVideo/JoinChannelVideo.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class JoinChannelVideoMain: BaseViewController {
6565
agoraKit = AgoraRtcEngineKit.sharedEngine(with: config, delegate: self)
6666

6767
// setup accessPointConfig
68-
if let ip = UserDefaults.standard.string(forKey: "private") {
68+
if let ip = GlobalSettings.shared.string(for: "private") {
6969
let accessPointConfig = AgoraLocalAccessPointConfiguration()
7070
accessPointConfig.mode = .localOnly
7171
accessPointConfig.ipList = [ip]

iOS/APIExample/ViewController.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ extension ViewController: SettingsViewControllerDelegate {
150150
LogUtils.log(message: "select \(setting.selectedOption().label) for \(key)", level: .info)
151151
}else if type == "TextFieldCell" {
152152
LogUtils.log(message: "select \(value) for \(key)", level: .info)
153-
UserDefaults.standard.set(value, forKey: key)
154-
UserDefaults.standard.synchronize()
153+
GlobalSettings.shared.setValue(key: key, value: value)
155154
}
156155
}
157156
}

0 commit comments

Comments
 (0)