真实设备上的 Sqlite 不能工作,但在模拟器上工作
SqlLite with real device not work but on simulator work
我正在使用 sqlLite with this library,所以当我在模拟器上 运行 时它运行良好,但是当我尝试 运行 一个真实的设备时它给了我这个错误
错误:
/var/mobile/Containers/Data/Application/B8B355F9-6378-4862-9D06-84DA3FD06366/Documents
2019-01-02 19:54:23.476422+0200 Test[3626:1280621] [logging-persist] cannot open file at line 42249 of [95fbac39ba]
2019-01-02 19:54:23.476491+0200 Test[3626:1280621] [logging-persist] os_unix.c:42249: (0) open(/var/mobile/Containers/Data/Application/B8B355F9-6378-4862-9D06-84DA3FD06366/DocumentsTest.sqlite3) - Undefined error: 0
Can't connect to DB, Error is: Error Domain=SQLite.Result Code=0 "(null)", [:]
以及我连接到 dp 的代码:
import Foundation
import SQLite
import SQLite3
class Database{
static let shared = Database()
public let connection: Connection?
public let databaseName = "Test.sqlite3"
init() {
let dbPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first as! String
print(dbPath)
do{
connection = try Connection("\(dbPath)\(databaseName)")
}catch{
connection = nil
let nserror = error as NSError
print("Can't connect to DB, Error is: \(nserror), \(nserror.userInfo)")
}
}
}
您需要加一个“/”
connection = try Connection("\(dbPath)/\(databaseName)")
我正在使用 sqlLite with this library,所以当我在模拟器上 运行 时它运行良好,但是当我尝试 运行 一个真实的设备时它给了我这个错误
错误:
/var/mobile/Containers/Data/Application/B8B355F9-6378-4862-9D06-84DA3FD06366/Documents
2019-01-02 19:54:23.476422+0200 Test[3626:1280621] [logging-persist] cannot open file at line 42249 of [95fbac39ba]
2019-01-02 19:54:23.476491+0200 Test[3626:1280621] [logging-persist] os_unix.c:42249: (0) open(/var/mobile/Containers/Data/Application/B8B355F9-6378-4862-9D06-84DA3FD06366/DocumentsTest.sqlite3) - Undefined error: 0 Can't connect to DB, Error is: Error Domain=SQLite.Result Code=0 "(null)", [:]
以及我连接到 dp 的代码:
import Foundation
import SQLite
import SQLite3
class Database{
static let shared = Database()
public let connection: Connection?
public let databaseName = "Test.sqlite3"
init() {
let dbPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first as! String
print(dbPath)
do{
connection = try Connection("\(dbPath)\(databaseName)")
}catch{
connection = nil
let nserror = error as NSError
print("Can't connect to DB, Error is: \(nserror), \(nserror.userInfo)")
}
}
}
您需要加一个“/”
connection = try Connection("\(dbPath)/\(databaseName)")