Skip to content

Instantly share code, notes, and snippets.

@perchrh
Created December 28, 2019 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perchrh/bffd4b3e64e431fdfcd6c2b56ad44e1d to your computer and use it in GitHub Desktop.
Save perchrh/bffd4b3e64e431fdfcd6c2b56ad44e1d to your computer and use it in GitHub Desktop.
manglende callbacks
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