-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert BraintreeDemoBTDataCollectorViewController to Swift
- Loading branch information
1 parent
080435c
commit eac05e7
Showing
5 changed files
with
94 additions
and
126 deletions.
There are no files selected for viewing
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
7 changes: 0 additions & 7 deletions
7
.../Features/Fraud Protection - BTDataCollector/BraintreeDemoBTDataCollectorViewController.h
This file was deleted.
Oops, something went wrong.
112 changes: 0 additions & 112 deletions
112
.../Features/Fraud Protection - BTDataCollector/BraintreeDemoBTDataCollectorViewController.m
This file was deleted.
Oops, something went wrong.
88 changes: 88 additions & 0 deletions
88
...tures/Fraud Protection - BTDataCollector/BraintreeDemoBTDataCollectorViewController.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import UIKit | ||
import CoreLocation | ||
import BraintreeDataCollector | ||
import BraintreeCore | ||
|
||
class BraintreeDemoBTDataCollectorViewController: BraintreeDemoPaymentButtonBaseViewController { | ||
|
||
let locationManager = CLLocationManager() | ||
var dataLabel = UILabel() | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
title = "Braintree Data Collector" | ||
createLocationPermissionButton() | ||
} | ||
|
||
override func createPaymentButton() -> UIView! { | ||
let dataCollectorButton = UIButton(type: .system) | ||
dataCollectorButton.setTitle("Collect Device Data", for: .normal) | ||
dataCollectorButton.setTitleColor(.blue, for: .normal) | ||
dataCollectorButton.setTitleColor(.lightGray, for: .highlighted) | ||
dataCollectorButton.setTitleColor(.lightGray, for: .disabled) | ||
dataCollectorButton.addTarget(self, action: #selector(tappedCollect), for: .touchUpInside) | ||
dataCollectorButton.translatesAutoresizingMaskIntoConstraints = false | ||
|
||
let label = UILabel() | ||
label.numberOfLines = 0 | ||
label.adjustsFontSizeToFitWidth = true | ||
label.translatesAutoresizingMaskIntoConstraints = false | ||
|
||
self.dataLabel = label | ||
|
||
let stackView = UIStackView(arrangedSubviews: [dataCollectorButton, label]) | ||
stackView.axis = .vertical | ||
stackView.spacing = 5 | ||
stackView.alignment = .center | ||
stackView.translatesAutoresizingMaskIntoConstraints = false | ||
|
||
NSLayoutConstraint.activate([ | ||
dataCollectorButton.heightAnchor.constraint(equalToConstant: 19.5), | ||
label.heightAnchor.constraint(equalToConstant: 19.5) | ||
]) | ||
|
||
return stackView | ||
} | ||
|
||
@objc func tappedCollect() { | ||
let dataCollector = BTDataCollector(apiClient: apiClient) | ||
|
||
progressBlock("Started collecting all data...") | ||
dataCollector.collectDeviceData { deviceData, error in | ||
guard let deviceData else { | ||
self.progressBlock(error?.localizedDescription) | ||
return | ||
} | ||
|
||
self.dataLabel.text = deviceData | ||
self.progressBlock("Collected all device data!") | ||
} | ||
} | ||
|
||
@objc func tappedRequestLocationAuthorization() { | ||
let locationStatus = locationManager.authorizationStatus | ||
|
||
switch locationStatus { | ||
case .notDetermined: | ||
locationManager.requestWhenInUseAuthorization() | ||
|
||
default: | ||
progressBlock("Location authorization requested previously. Update authorization in Settings app.") | ||
} | ||
} | ||
|
||
private func createLocationPermissionButton() { | ||
let obtainLocationPermissionButton = UIButton(type: .system) | ||
obtainLocationPermissionButton.setTitle("Obtain Location Permission", for: .normal) | ||
obtainLocationPermissionButton.setTitleColor(.blue, for: .normal) | ||
obtainLocationPermissionButton.addTarget(self, action: #selector(tappedRequestLocationAuthorization), for: .touchUpInside) | ||
obtainLocationPermissionButton.translatesAutoresizingMaskIntoConstraints = false | ||
|
||
view.addSubview(obtainLocationPermissionButton) | ||
|
||
NSLayoutConstraint.activate([ | ||
obtainLocationPermissionButton.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -10), | ||
obtainLocationPermissionButton.centerXAnchor.constraint(equalTo: view.centerXAnchor) | ||
]) | ||
} | ||
} |
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