This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import KeychainSwift | |
struct KeychainWrapper { | |
static let shared = KeychainWrapper() | |
let keychain = KeychainSwift() | |
func store(key: String, value: String) { | |
keychain.set(value, forKey: key) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func registration(credentials: ASAuthorizationAppleIDCredential) { | |
let emailSuccess = KeychainWrapper.shared.set(key: "email", value: credentials.email!) | |
let userSuccess = KeychainWrapper.shared.set(key: "user", value: credentials.user) | |
let name = (credentials.fullName?.givenName ?? "") + (credentials.fullName?.familyName ?? "") | |
KeychainWrapper.shared.set(key: "name", value: name) | |
if emailSuccess, userSuccess { | |
signInSucceeded(emailSuccess) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func performSignIn(using requests: [ASAuthorizationRequest]) { | |
appleSignInDelegates = AppleSignInDelegate(window: window) { success in | |
if success { | |
// update UI | |
self.actionState = 1 | |
print("Update UI") | |
} else { | |
// show the user an error | |
print("error in perform signin") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static let sharedManager: SessionManager = { | |
let configuration = URLSessionConfiguration.default | |
configuration.httpAdditionalHeaders = SessionManager.defaultHTTPHeaders | |
configuration.timeoutIntervalForRequest = 20 | |
configuration.timeoutIntervalForResource = 20 | |
let manager = Alamofire.SessionManager(configuration: configuration) | |
let requestRet = NetworkRequestRetrier() | |
manager.retrier = requestRet | |
return manager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Alamofire | |
class ApiManager:NSObject | |
{ | |
private var retriedRequests: [String: Int] = [:] | |
public typealias successHandler = (Data) -> () | |
public typealias failureHandler = (Error) -> () | |
static let sharedManager: SessionManager = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Alamofire | |
class NetworkRequestRetrier: RequestRetrier { | |
let retry = 3 // set the count for number of retries | |
// [Request url: Number of times retried] | |
private var retriedRequests: [String: Int] = [:] | |
func should(_ manager: SessionManager, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension PHAsset { | |
static let imageSize = CGSize(width: 400, height: 400) | |
class func getImageFrom(url : String, completion : @escaping (_ image : UIImage?) -> ()) { | |
// retrieve the list of matching results for your asset url | |
let assetUrl = URL(string: url)! | |