Created
December 28, 2019 13:59
-
-
Save perchrh/bffd4b3e64e431fdfcd6c2b56ad44e1d to your computer and use it in GitHub Desktop.
manglende callbacks
This file contains hidden or 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 setupSentiance(completion: (() -> Void)? = nil, failure: ((_ error: SentianceError) -> Void)? = nil) { | |
if CLLocationManager.authorizationStatus() != .authorizedAlways, CMMotionActivityManager.authorizationStatus() != .authorized { return } | |
guard let realm = try? Realm(), let _ = realm.objects(User.self).first else { return } | |
if let isInitialised = SENTSDK.sharedInstance()?.getInitState() { | |
if isInitialised == .SENTInitInProgress { return } | |
if isInitialised == .SENTInitialized { | |
if let sdkStatus = SENTSDK.sharedInstance()?.getStatus()?.startStatus, sdkStatus == .started { | |
completion?() | |
delegates |> { delegate in | |
delegate.sentianceStarted() | |
} | |
} else { | |
startSentiance(completion: completion, failure: failure) | |
} | |
return | |
} | |
} | |
if let appId = KeychainWrapper.standard.string(forKey: ConfigKey.sentianceAppId.rawValue), let appSecret = KeychainWrapper.standard.string(forKey: ConfigKey.sentianceAppSecret.rawValue) { | |
self.initSentianceWithAppId(appId, appSecret: appSecret, completion: completion, failure: failure) | |
} else { | |
fetchConfig(success: { (config) in | |
if let sentianceAppID = config[ConfigKey.sentianceAppId], | |
let sentianceAppSecret = config[ConfigKey.sentianceAppSecret] { | |
self.initSentianceWithAppId(sentianceAppID, appSecret: sentianceAppSecret, completion: completion, failure: failure) | |
} | |
}) { (error) in | |
failure?(.unretrievableConfig) | |
return | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment