12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- import UIKit
- let DATABASE_DB_NAME = "CommonFrame_2"
- let DATABASE_DB_EXT = "db"
- let DATABASE_DB_ALL_NAME = "\(DATABASE_DB_NAME).\(DATABASE_DB_EXT)"
- class CommonDBManager: NSObject {
-
- class func getDBPath() -> String {
- if CommonValue.getDBPath() != "" {
- return CommonUntils.getAppPath() + CommonValue.getDBPath()
- } else {
- return NSHomeDirectory() + "/Documents/" + DATABASE_DB_ALL_NAME
- }
- }
- class func initDB() {
-
- let searchPaths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
- let documentFolderPath = searchPaths[0]
- let dbFilePath = documentFolderPath + "/"+DATABASE_DB_ALL_NAME
- print("==DBPath:\(dbFilePath)")
- let fm = FileManager.default
- let isExist = fm.fileExists(atPath: dbFilePath)
-
- if !isExist {
- let backupDbPath = Bundle.main.path(forResource: DATABASE_DB_NAME, ofType: DATABASE_DB_EXT)
- do {
- _ = try fm.copyItem(atPath: backupDbPath!, toPath: dbFilePath)
- } catch {
- }
- } else {
- print(getDBPath())
-
- }
- }
- }
|