Skip to content

Commit

Permalink
SQLite deactivated due inaccessibility in Target extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelsetragni committed Mar 15, 2023
1 parent 0a05846 commit 2566999
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 53 deletions.
2 changes: 1 addition & 1 deletion IosAwnCore.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'IosAwnCore'
s.version = '0.7.4-pre.1'
s.version = '0.7.4-pre.2'
s.summary = 'Awesome Notifications iOS Core'

s.description = <<-DESC
Expand Down
31 changes: 20 additions & 11 deletions IosAwnCore/Classes/databases/SQLitePrimitivesDB.swift
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,11 @@ public class SQLitePrimitivesDB {
return .success((value == 1) as? T)

case is String.Type:
let value = String(cString: sqlite3_column_text(statement, 0))
return .success(value as? T)
let value = sqlite3_column_text(statement, 0)
if value != nil {
return .success(String(cString: value!) as? T)
}
return .success(nil)

default:
return .failure(SQLiteError.invalidParameterType)
Expand Down Expand Up @@ -355,7 +358,9 @@ public class SQLitePrimitivesDB {
defer { sqlite3_finalize(statement) }

while sqlite3_step(statement) == SQLITE_ROW {
count = Int(sqlite3_column_int(statement, 0))
let value = sqlite3_column_int(statement, 0)
if value != nil { count = Int(value) }
else { count = 0 }
}
return .success(count)

Expand Down Expand Up @@ -412,10 +417,12 @@ public class SQLitePrimitivesDB {
defer { sqlite3_finalize(statement) }

while sqlite3_step(statement) == SQLITE_ROW {
let key = String(cString: sqlite3_column_text(statement, 0))
let value = valueGetter(statement)

values[key] = value
let rawValue = sqlite3_column_text(statement, 0)
if rawValue != nil {
let key = String(cString: rawValue!)
let value = valueGetter(statement)
values[key] = value
}
}
return .success(values)

Expand Down Expand Up @@ -476,10 +483,12 @@ public class SQLitePrimitivesDB {
defer { sqlite3_finalize(statement) }

while sqlite3_step(statement) == SQLITE_ROW {
let key = String(cString: sqlite3_column_text(statement, 0))
let value = valueGetter(statement)

values[key] = value
let rawValue = sqlite3_column_text(statement, 0)
if rawValue != nil {
let key = String(cString: rawValue!)
let value = valueGetter(statement)
values[key] = value
}
}
return .success(values)

Expand Down
55 changes: 14 additions & 41 deletions IosAwnCore/Classes/managers/LocalizationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,29 @@ import Foundation
class LocalizationManager {
static let shared = LocalizationManager()

let _userDefaults = UserDefaults(suiteName: Definitions.USER_DEFAULT_TAG)
let localizationKey = "awn_localization_languageCode"

func setLocalization(languageCode: String? = nil) -> Bool {
let langCode =
languageCode ??
Locale.preferredLanguages[0]

switch SQLitePrimitivesDB.shared.setString(
tag: "localization",
key: "languageCode",
value: langCode
guard let userDefaults = _userDefaults ?? UserDefaults(suiteName: Definitions.USER_DEFAULT_TAG)
else { return false }

let langCode =
(languageCode ?? Locale.preferredLanguages[0])
.lowercased()
.replacingOccurrences(of: "_", with: "-")
) {
case .success():
return true
case .failure(let error):
let awnError = ExceptionFactory.shared.createNewAwesomeException(
className: "LocalizationManager",
code: ExceptionCode.CODE_INSUFFICIENT_PERMISSIONS,
message: "SQLitePrimitivesDB is not available \(error.localizedDescription)",
detailedCode: ExceptionCode.DETAILED_INSUFFICIENT_PERMISSIONS+".setLocalization"
)
print(awnError)
return false
}

userDefaults.set(langCode, forKey: localizationKey)

return true
}

func getLocalization() -> String {
let appLangCode = Locale.preferredLanguages[0]

switch SQLitePrimitivesDB.shared.getString(
tag: "localization",
key: "languageCode"
) {

case .success(let value):
return (value ?? appLangCode)
.lowercased()
.replacingOccurrences(of: "_", with: "-")

case .failure(let error):
let error = ExceptionFactory.shared.createNewAwesomeException(
className: "LocalizationManager",
code: ExceptionCode.CODE_INSUFFICIENT_PERMISSIONS,
message: "SQLitePrimitivesDB is not available \(error.localizedDescription)",
detailedCode: ExceptionCode.DETAILED_INSUFFICIENT_PERMISSIONS+".getLocalization"
)
print(error)
return appLangCode
let awnLangCode = _userDefaults?.string(forKey: localizationKey)
return (awnLangCode ?? appLangCode)
.lowercased()
.replacingOccurrences(of: "_", with: "-")
}
}
}

0 comments on commit 2566999

Please sign in to comment.