gpt4 book ai didi

swift - 当用户输入地理围栏半径时将当前位置保存到 plist

转载 作者:行者123 更新时间:2023-11-30 11:02:28 25 4
gpt4 key购买 nike

我正在开发一个地理围栏应用程序。当用户输入我从数据库文件中提取的地理围栏半径时,我需要将用户当前位置保存到 plist 中。怎么做?我是新来的。请帮助..我像这样从数据库文件中提取..

func readvalues(){

let path = Bundle.main.path(forResource: "NewFile", ofType: "db")


let database = FMDatabase(path: path)
if !database.open() {
print("Unable to open database")
return
}

if let rs = database.executeQuery("SELECT * FROM myowntable", withArgumentsIn: []) {

while rs.next() {

print("%@", rs);
geotifications = []
let longitude = rs.string(forColumn: "longitude") as! String
let latitude = rs.string(forColumn: "latitude") as! String
let note = rs.string(forColumn: "note") as! String
let radiusstring = rs.string(forColumn: "radius") as! String
let radius = (radiusstring as NSString).doubleValue
let identifier = rs.string(forColumn: "identifier") as! String
let event = Int(rs.string(forColumn: "eventType")!)!
let eventType: EventType = (event == 0) ? .onEntry : .onExit
let location:CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: (latitude as NSString).doubleValue, longitude: (longitude as NSString).doubleValue)


self.addGeotificationViewController(didAddCoordinate: location, radius: radius, identifier: identifier, note: note, eventType: eventType)


}

} else {
print("executeQuery failed: \(database.lastErrorMessage())")
}

database.close()

}

最佳答案

您无法更改应用程序 plist 文件,因此您需要创建自己的 plist 文件

让 fileManager = FileManager.default

let documentDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
let path = documentDirectory.appending("/geo.plist")

if(!fileManager.fileExists(atPath: path)){
print(path)

let data : [String: String] = [
"geoPointX": "20",
"geoPointY": "30"

]

let someData = NSDictionary(dictionary: data)
let isWritten = someData.write(toFile: path, atomically: true)
print("is the file created: \(isWritten)")



} else {
print("file exists")
}

关于swift - 当用户输入地理围栏半径时将当前位置保存到 plist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53166772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com