Skip to content

Commit

Permalink
Updates to support iOS 9.0 and above
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhawak committed Mar 22, 2021
1 parent 5486e34 commit 9b8c1a5
Show file tree
Hide file tree
Showing 54 changed files with 7,119 additions and 12,899 deletions.
8 changes: 4 additions & 4 deletions BaatoSwift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Pod::Spec.new do |spec|

spec.name = "BaatoSwift"
spec.version = "0.1.8"
spec.version = "0.1.9"
spec.summary = "This framework help to consume baato api."
spec.description = <<-DESC
Baato Swift is a framework developed for consuming the baato api efficiently.
Expand All @@ -13,17 +13,17 @@ Pod::Spec.new do |spec|

spec.author = { "Bhawak Pokhrel" => "bhawak.pokhrel@gmail.com" }

spec.platform = :ios, "10.3"
spec.platform = :ios, "9.0"

spec.source = { :git => "https://github.com/baato/BaatoSwift.git", :tag => "#{spec.version}" }

spec.source_files = "BaatoSwift/**/*.{swift}"
# spec.resources = "BaatoSwift/**/*.{plist}"

spec.requires_arc = true
spec.swift_version = "5"
spec.swift_version = "4"
# spec.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
spec.dependency "Alamofire", "~> 5.2"
spec.dependency "Alamofire", "~> 4.0"
spec.dependency "GEOSwift"
spec.dependency "geos"

Expand Down
16 changes: 10 additions & 6 deletions BaatoSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -437,7 +437,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = NO;
Expand All @@ -458,24 +458,26 @@
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = DTCKQRUUGB;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = BaatoSwift/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.1;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.mobera.BaatoSwift;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = NO;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALID_ARCHS = "arm64 arm64e armv7 armv7s x86_64";
};
Expand All @@ -488,24 +490,26 @@
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = DTCKQRUUGB;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = BaatoSwift/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.1;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.mobera.BaatoSwift;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = NO;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALID_ARCHS = "arm64 arm64e armv7 armv7s x86_64";
};
Expand Down
139 changes: 111 additions & 28 deletions BaatoSwift/API/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ public class API {
self.instructions = instructions
}
}

init() {
self.base = "https://api.baato.io"
self.root = base + "/api/v1"
Expand All @@ -223,7 +222,12 @@ public class API {
requestParameters.removeAll()
//compulsory ones
guard let token = token else {
os_log("Error request %@%@: %@", log: OSLog.default, type: .error, "Invalid request", "Baato API", "Token Not Found")
if #available(iOS 10.0, *) {
os_log("Error request %@%@: %@", log: OSLog.default, type: .error, "Invalid request", "Baato API", "Token Not Found")
} else {
print("Token Not Found");
// Fallback on earlier versions
}
return
}
requestParameters["key"] = token
Expand All @@ -232,7 +236,11 @@ public class API {
//Required
freshInitialize()
guard let query = query else {
os_log("Error request %@%@: %@", log: OSLog.default, type: .error, "Invalid request", "Search Query", "No Query Parameters")
if #available(iOS 10.0, *) {
os_log("Error request %@%@: %@", log: OSLog.default, type: .error, "Invalid request", "Search Query", "No Query Parameters")
} else {
print("No Query Parameters");
}
return
}
requestParameters["q"] = query
Expand All @@ -258,11 +266,21 @@ public class API {
//Required
freshInitialize()
guard let lat = lat else {
os_log("Error request %@%@: %@", log: OSLog.default, type: .error, "Invalid request", "Reverse Query", "Latitide is required")
if #available(iOS 10.0, *) {
os_log("Error request %@%@: %@", log: OSLog.default, type: .error, "Invalid request", "Reverse Query", "Latitide is required")
} else {
print("Latitide is required");
// Fallback on earlier versions
}
return
}
guard let lon = lon else {
os_log("Error request %@%@: %@", log: OSLog.default, type: .error, "Invalid request", "Reverse Query", "Longitude is required")
if #available(iOS 10.0, *) {
os_log("Error request %@%@: %@", log: OSLog.default, type: .error, "Invalid request", "Reverse Query", "Longitude is required")
} else {
print("Longitude is required");
// Fallback on earlier versions
}
return
}

Expand All @@ -280,7 +298,12 @@ public class API {
freshInitialize()

guard let place = place else {
os_log("Error request %@%@: %@", log: OSLog.default, type: .error, "Invalid request", "Place Query", "Place ID is required")
if #available(iOS 10.0, *) {
os_log("Error request %@%@: %@", log: OSLog.default, type: .error, "Invalid request", "Place Query", "Place ID is required")
} else {
print("Place ID is required");
// Fallback on earlier versions
}
return
}
requestParameters["placeId"] = place
Expand All @@ -289,7 +312,12 @@ public class API {
//Required
freshInitialize()
guard let sLat = sLat, let sLon = sLon, let dLat = dLat, let dLon = dLon else {
os_log("Error request %@%@: %@", log: OSLog.default, type: .error, "Invalid request", "Route Query", "Start and End Coordinates are required")
if #available(iOS 10.0, *) {
os_log("Error request %@%@: %@", log: OSLog.default, type: .error, "Invalid request", "Route Query", "Start and End Coordinates are required")
} else {
print("Start and End Coordinates are required");
// Fallback on earlier versions
}
return
}
let points: [String] = ["\(sLat)," + "\(sLon)", "\(dLat)," + "\(dLon)"]
Expand All @@ -315,7 +343,12 @@ public class API {
//Required
freshInitialize()
guard let sLat = sLat, let sLon = sLon, let dLat = dLat, let dLon = dLon else {
os_log("Error request %@%@: %@", log: OSLog.default, type: .error, "Invalid request", "Route Query", "Start and End Coordinates are required")
if #available(iOS 10.0, *) {
os_log("Error request %@%@: %@", log: OSLog.default, type: .error, "Invalid request", "Route Query", "Start and End Coordinates are required")
} else {
print("Start and End Coordinates are required");
// Fallback on earlier versions
}
return
}
let points: [String] = ["\(sLat)," + "\(sLon)", "\(dLat)," + "\(dLon)"]
Expand All @@ -341,10 +374,10 @@ public class API {
}
}
extension API {
public func getSearch(completion: @escaping(Result<[SearchResult]?,Error>) -> Void) {
public func getSearch(completion: @escaping(Result<[SearchResult]?>) -> Void) {
mapQuerySearch()
let searchFilter = requestParameters
let request = AF.request(search!, method: .get, parameters: searchFilter)
let request = Alamofire.request(search!, method: .get, parameters: searchFilter)
request.validate(statusCode: 200..<300)
request.validate(contentType: ["application/json"])
request.responseJSON { response in
Expand All @@ -371,14 +404,19 @@ extension API {
// completion(searchResult)
case .failure:
completion(.failure(response.error!))
os_log("[Refresh Request] Request failed", log: OSLog.default, type: .error)
if #available(iOS 10.0, *) {
os_log("[Refresh Request] Request failed", log: OSLog.default, type: .error)
} else {
print("[Refresh Request] Request failed");
// Fallback on earlier versions
}
}
}
}
public func getReverse(completion: @escaping(Result<Place?, Error>) -> Void) {
public func getReverse(completion: @escaping(Result<Place?>) -> Void) {
mapQueryReverse()
let filter = requestParameters
let request = AF.request(reverse!, method: .get, parameters: filter)
let request = Alamofire.request(reverse!, method: .get, parameters: filter)
request.validate(statusCode: 200..<300)
request.validate(contentType: ["application/json"])
request.responseJSON { response in
Expand All @@ -387,7 +425,12 @@ extension API {
case .success:
guard let data = response.data, let value = try? JSONDecoder().decode(ResponseType.self, from: data) else {
completion(.failure(BaatoError.emptyResponse))
os_log("[Refresh Request] Error parsing JSON", log: OSLog.default, type: .error)
if #available(iOS 10.0, *) {
os_log("[Refresh Request] Error parsing JSON", log: OSLog.default, type: .error)
} else {
print("[Refresh Request] Error parsing JSON");
// Fallback on earlier versions
}
return
}
do {
Expand All @@ -399,15 +442,20 @@ extension API {
}
case .failure:
completion(.failure(response.error!))
os_log("[Refresh Request] Request failed", log: OSLog.default, type: .error)
if #available(iOS 10.0, *) {
os_log("[Refresh Request] Request failed", log: OSLog.default, type: .error)
} else {
print("[Refresh Request] Request failed");
// Fallback on earlier versions
}
}
}

}
public func getPlaces(completion: @escaping(Result<Place?,Error>) -> Void) {
public func getPlaces(completion: @escaping(Result<Place?>) -> Void) {
mapQueryPlace()
let filter = requestParameters
let request = AF.request(places!, method: .get, parameters: filter)
let request = Alamofire.request(places!, method: .get, parameters: filter)
request.validate(statusCode: 200..<300)
request.validate(contentType: ["application/json"])
request.responseJSON { response in
Expand All @@ -416,7 +464,12 @@ extension API {
case .success:
guard let data = response.data, let value = try? JSONDecoder().decode(ResponseType.self, from: data) else {
completion(.failure(BaatoError.emptyResponse))
os_log("[Refresh Request] Error parsing JSON", log: OSLog.default, type: .error)
if #available(iOS 10.0, *) {
os_log("[Refresh Request] Error parsing JSON", log: OSLog.default, type: .error)
} else {
print("[Refresh Request] Error parsing JSON");
// Fallback on earlier versions
}
return
}
do {
Expand All @@ -430,14 +483,19 @@ extension API {

case .failure:
completion(.failure(response.error!))
os_log("[Refresh Request] Request failed", log: OSLog.default, type: .error)
if #available(iOS 10.0, *) {
os_log("[Refresh Request] Request failed", log: OSLog.default, type: .error)
} else {
print("[Refresh Request] Request failed");
// Fallback on earlier versions
}
}
}
}
public func getDirections(completion: @escaping(Result<[NavResponse]?,Error>) -> Void) {
public func getDirections(completion: @escaping(Result<[NavResponse]?>) -> Void) {
mapQueryDirections()
let filter = requestParameters
let request = AF.request(directions!, method: .get, parameters: filter)
let request = Alamofire.request(directions!, method: .get, parameters: filter)
request.validate(statusCode: 200..<300)
request.validate(contentType: ["application/json"])
request.responseJSON { response in
Expand All @@ -446,7 +504,12 @@ extension API {
case .success:
guard let data = response.data, let value = try? JSONDecoder().decode(ResponseType.self, from: data) else {
completion(.failure(BaatoError.emptyResponse))
os_log("[Refresh Request] Error parsing JSON", log: OSLog.default, type: .error)
if #available(iOS 10.0, *) {
os_log("[Refresh Request] Error parsing JSON", log: OSLog.default, type: .error)
} else {
print("[Refresh Request] Error parsing JSON");
// Fallback on earlier versions
}
return
}
while !value.data.isAtEnd {
Expand All @@ -465,14 +528,19 @@ extension API {

case .failure:
completion(.failure(response.error!))
os_log("[Refresh Request] Request failed", log: OSLog.default, type: .error)
if #available(iOS 10.0, *) {
os_log("[Refresh Request] Request failed", log: OSLog.default, type: .error)
} else {
print("[Refresh Request] Request failed");
// Fallback on earlier versions
}
}
}
}
public func getMapboxDirections(completion: @escaping(Result<Data?,Error>) -> Void) {
public func getMapboxDirections(completion: @escaping(Result<Data?>) -> Void) {
mapboxQueryDirections()
let filter = requestParameters
let request = AF.request(directions!, method: .get, parameters: filter)
let request = Alamofire.request(directions!, method: .get, parameters: filter)
request.validate(statusCode: 200..<300)
request.validate(contentType: ["application/json"])
request.responseJSON { response in
Expand All @@ -481,21 +549,36 @@ extension API {

guard let data = response.data else {
completion(.failure(BaatoError.parseError))
os_log("[Refresh Request] Error parsing JSON", log: OSLog.default, type: .error)
if #available(iOS 10.0, *) {
os_log("[Refresh Request] Error parsing JSON", log: OSLog.default, type: .error)
} else {
print("[Refresh Request] Error parsing JSON");
// Fallback on earlier versions
}
return
}
completion(.success(data))

case .failure:
completion(.failure(response.error!))
os_log("[Refresh Request] Request failed", log: OSLog.default, type: .error)
if #available(iOS 10.0, *) {
os_log("[Refresh Request] Request failed", log: OSLog.default, type: .error)
} else {
print("[Refresh Request] Request failed");
// Fallback on earlier versions
}
}
}
}

public func getmapstyle(){
}
fileprivate func reportErrorFetching(_ type: String, identifier: Int? = nil, reason: String) {
os_log("Error fetching %@%@: %@", log: OSLog.default, type: .error, type, identifier != nil ? " \(identifier!)" : "", reason)
if #available(iOS 10.0, *) {
os_log("Error fetching %@%@: %@", log: OSLog.default, type: .error, type, identifier != nil ? " \(identifier!)" : "", reason)
} else {
print("Error fetching data");
// Fallback on earlier versions
}
}
}
Loading

0 comments on commit 9b8c1a5

Please sign in to comment.