Skip to content

Instantly share code, notes, and snippets.

@vialyx
Last active October 8, 2019 08:26
Show Gist options
  • Save vialyx/b57ea6fedeab75934990f7d7cf5b1b25 to your computer and use it in GitHub Desktop.
Save vialyx/b57ea6fedeab75934990f7d7cf5b1b25 to your computer and use it in GitHub Desktop.
class ViewController: UIViewController {
var model: Model = Model()
override func loadView() {
super.loadView()
let button = UIButton(frame: CGRect(x: 60, y: 100, width: 200, height: 100))
button.setTitle("Start Fitbit Auth", for: UIControl.State())
button.backgroundColor = .red
button.addTarget(self, action: #selector(authDidTap), for: .touchUpInside)
view.addSubview(button)
}
// MARK: - Actions
@objc private func authDidTap() {
if let context = UIApplication.shared.keyWindow {
model.contextProvider = AuthContextProvider(context)
}
model.auth { authCode, error in
if error != nil {
print("Auth flow finished with error \(String(describing: error))")
} else {
print("Your auth code is \(String(describing: authCode))")
DispatchQueue.main.async {
let alert = UIAlertController(title: "Success", message: "auth code is \(String(describing: authCode))", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default))
self.present(alert, animated: true)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment