2021-09-03 13:57:15 -05:00
|
|
|
//
|
|
|
|
|
// UIDevice+Vibration.swift
|
|
|
|
|
// AltStore
|
|
|
|
|
//
|
|
|
|
|
// Created by Riley Testut on 9/1/21.
|
|
|
|
|
// Copyright © 2021 Riley Testut. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import AudioToolbox
|
|
|
|
|
import CoreHaptics
|
2023-03-01 14:36:52 -05:00
|
|
|
import UIKit
|
2021-09-03 13:57:15 -05:00
|
|
|
|
2023-03-01 00:48:36 -05:00
|
|
|
private extension SystemSoundID {
|
2021-09-03 13:57:15 -05:00
|
|
|
static let pop = SystemSoundID(1520)
|
|
|
|
|
static let cancelled = SystemSoundID(1521)
|
|
|
|
|
static let tryAgain = SystemSoundID(1102)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@available(iOS 13, *)
|
2023-03-01 00:48:36 -05:00
|
|
|
extension UIDevice {
|
|
|
|
|
enum VibrationPattern {
|
2021-09-03 13:57:15 -05:00
|
|
|
case success
|
|
|
|
|
case error
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@available(iOS 13, *)
|
2023-03-01 00:48:36 -05:00
|
|
|
extension UIDevice {
|
2021-09-03 13:57:15 -05:00
|
|
|
var isVibrationSupported: Bool {
|
2023-03-01 00:48:36 -05:00
|
|
|
CHHapticEngine.capabilitiesForHardware().supportsHaptics
|
2021-09-03 13:57:15 -05:00
|
|
|
}
|
|
|
|
|
|
2023-03-01 00:48:36 -05:00
|
|
|
func vibrate(pattern: VibrationPattern) {
|
|
|
|
|
guard isVibrationSupported else { return }
|
|
|
|
|
|
|
|
|
|
switch pattern {
|
2021-09-03 13:57:15 -05:00
|
|
|
case .success: AudioServicesPlaySystemSound(.tryAgain)
|
|
|
|
|
case .error: AudioServicesPlaySystemSound(.cancelled)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|