我正在开发地理围栏应用程序。当用户输入地理围栏半径时,我需要将用户当前位置保存到plist中,该半径已从db文件中提取出来。怎么做?我是新来的。请帮助..我是从数据库文件中提取出来的。.
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()
}
答案 0 :(得分:0)
您无法更改应用程序的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")
}