Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let package = Package(
dependencies: [
.product(name: "SwiftyJSON", package: "SwiftyJSON"),
.product(name: "GRDB", package: "GRDB.swift"),
.product(name: "Reachability", package: "Reachability.swift")
.product(name: "Reachability", package: "Reachability.swift", condition: .when(platforms: [.iOS]))
]
),
.testTarget(
Expand Down
2 changes: 1 addition & 1 deletion Sources/com.awareframework.ios.core/AwareSensor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public protocol ISensorController {
func set(label:String)
}

open class AwareSensor: NSObject,ISensorController {
open class AwareSensor: NSObject, ISensorController {

public let notificationCenter = NotificationCenter.default
public var syncState = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ open class DbSyncHelper: NSObject, URLSessionDelegate, URLSessionDataDelegate, U
self.urlSession(session, task: task, didCompleteWithError: nil)
}
}

}

//////////
Expand Down
24 changes: 22 additions & 2 deletions Sources/com.awareframework.ios.core/db/sqlite/SQLiteEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ open class SQLiteEngine: Engine {
let instance = self.getSQLiteInstance()
try instance?.write{ db in
for d in data {
if let result = handler(d) as? PersistableRecord {
if let result = handler(d) as? (any PersistableRecord) {
try result.insert(db)
}
}
Expand All @@ -69,7 +69,7 @@ open class SQLiteEngine: Engine {
}
}

open func save(_ data: Array<BaseDbModelSQLite>, completion:((Error?)->Void)?){
open func save(_ data: Array<any BaseDbModelSQLite>, completion:((Error?)->Void)?){
do {
let instance = self.getSQLiteInstance()
try instance?.write{ db in
Expand Down Expand Up @@ -199,6 +199,26 @@ open class SQLiteEngine: Engine {

}


func getAllTableNames(in dbQueue: DatabaseQueue) throws -> [String] {
return try dbQueue.read { db in
try String.fetchAll(db, sql: """
SELECT name FROM sqlite_master
WHERE type = 'table' AND name NOT LIKE 'sqlite_%'
ORDER BY name
""")
}
}

func hasTable(_ tableName:String, in dbQueue: DatabaseQueue) throws -> Bool{
let tables = try getAllTableNames(in: dbQueue)
return tables.contains { element in
if element == tableName {
return true
}
return false
}
}

}

27 changes: 17 additions & 10 deletions Sources/com.awareframework.ios.core/manager/DbSyncManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

import Foundation
import UIKit

#if canImport(Reachability) && os(iOS)
import Reachability
#endif

open class DbSyncManager {

Expand Down Expand Up @@ -127,20 +130,24 @@ open class DbSyncManager {
@objc public func sync(_ force:Bool=false){

if CONFIG.batteryChargingOnly && force == false {
switch UIDevice.current.batteryState {
case .unknown,.unplugged:
return
default:
break
}
#if canImport(Reachability) && os(iOS)
switch UIDevice.current.batteryState {
case .unknown,.unplugged:
return
default:
break
}
#endif
}

if CONFIG.wifiOnly && force == false {
do {
let reachability = try Reachability()
if reachability.connection == .cellular || reachability.connection == .unavailable {
return
}
#if canImport(Reachability) && os(iOS)
let reachability = try Reachability()
if reachability.connection == .cellular || reachability.connection == .unavailable {
return
}
#endif
}catch {
print(error)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public protocol BaseDbModelSQLite: Codable, FetchableRecord, PersistableRecord {

func toDictionary() -> Dictionary<String, Any>

static func createTable(queue: DatabaseQueue)
static func createTable(queue: DatabaseQueue) throws
static var databaseTableName: String { get }
}
10 changes: 10 additions & 0 deletions Sources/com.awareframework.ios.core/util/AwareUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
//

import Foundation
#if os(iOS)
import UIKit
#elseif os(watchOS)
import WatchKit
#endif

public class AwareUtils{

Expand All @@ -21,7 +25,13 @@ public class AwareUtils{
if let deviceId = UserDefaults.standard.string(forKey: kDeviceIdKey) {
return deviceId
}else{

#if os(watchOS)
let deviceId = WKInterfaceDevice.current().identifierForVendor?.uuidString
#else
let deviceId = UIDevice.current.identifierForVendor?.uuidString
#endif

if let did = deviceId {
UserDefaults.standard.set(did, forKey: kDeviceIdKey)
return did
Expand Down