Skip to content

Instantly share code, notes, and snippets.

View SamStone92's full-sized avatar

Sam Stone SamStone92

  • Gloucester, UK
View GitHub Profile
func showNilError() {
let alert = UIAlertController(title: "No Heart Rate Data Found", message: "There was no heart rate data found for the selected dates. If you expected to see data, it may be that ARTRate is not authorised to read you heart rate data. Please go to the settings app (Privacy -> HealthKit) to change this.", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Okay", style: .cancel, handler: nil))
alert.addAction(UIAlertAction(title: "Go to settings", style: .default, handler: { action in
if let url = URL(string:UIApplicationOpenSettingsURLString) {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
} }))
self.present(alert, animated: true, completion: nil)
let health = HKHealthStore()
let heartRateType:HKQuantityType = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.heartRate)!
var shownWarning : Bool = false
func getHeartRateData()
{
let startDate = Calendar.current.date(byAdding: .day, value: -5, to: Date())!
let endDate = Date()
let predicate = HKQuery.predicateForSamples(withStart: startDate, end: endDate, options: [])
let sortDescriptors = [
let heartRateType:HKQuantityType = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.heartRate)!
HKHealthStore().requestAuthorization(toShare: nil, read: [heartRateType]) {(success, error) in
print(success)
//Success will always be equal to true unless a genuine error occurs
}
extension LABiometryType {
var toString : String {
switch self {
case .none:
return "your iPhone pin"
case .faceID:
return "FaceID"
case .touchID:
return "TouchID"
}
extension LABiometryType {
var toString : String {
switch self {
case .none:
return "your iPhone pin"
case .faceID:
return "FaceID"
case .touchID:
return "TouchID"
}
func navigationController(_ navigationController: UINavigationController, interactionControllerFor animationController: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
guard let ci = customInteractor else { return nil }
return ci.transitionInProgress ? customInteractor : nil
}
func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
guard let frame = self.selectedFrame else { return nil }
guard let song = self.selectedSong else { return nil }
switch operation {
case .push:
self.customInteractor = CustomInteractor(attachTo: toVC)
return CustomAnimator(duration: TimeInterval(UINavigationControllerHideShowBarDuration), isPresenting: true, originFrame: frame, image: song.artwork)
default:
return CustomAnimator(duration: TimeInterval(UINavigationControllerHideShowBarDuration), isPresenting: false, originFrame: frame, image: song.artwork)
@objc private func handleBackGesture(_ gesture : UIScreenEdgePanGestureRecognizer) {
let viewTranslation = gesture.translation(in: gesture.view?.superview)
var progress = viewTranslation.x / self.navigationController.view.frame.width
switch gesture.state {
case .began:
transitionInProgress = true
navigationController.popViewController(animated: true)
break
case .changed:
let viewTranslation = gesture.translation(in: gesture.view?.superview)
var progress = viewTranslation.x / self.navigationController.view.frame.width
private func setupBackGesture(view : UIView) {
let swipeBackGesture = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(handleBackGesture(_:)))
swipeBackGesture.edges = .left
view.addGestureRecognizer(swipeBackGesture)
}
@objc private func handleBackGesture(_ gesture : UIScreenEdgePanGestureRecognizer) {
}