mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
47 lines
933 B
Swift
47 lines
933 B
Swift
|
|
//
|
||
|
|
// UIDevice+Vibration.swift
|
||
|
|
// AltStore
|
||
|
|
//
|
||
|
|
// Created by Riley Testut on 9/1/21.
|
||
|
|
// Copyright © 2021 Riley Testut. All rights reserved.
|
||
|
|
//
|
||
|
|
|
||
|
|
import AudioToolbox
|
||
|
|
import CoreHaptics
|
||
|
|
|
||
|
|
private extension SystemSoundID
|
||
|
|
{
|
||
|
|
static let pop = SystemSoundID(1520)
|
||
|
|
static let cancelled = SystemSoundID(1521)
|
||
|
|
static let tryAgain = SystemSoundID(1102)
|
||
|
|
}
|
||
|
|
|
||
|
|
@available(iOS 13, *)
|
||
|
|
extension UIDevice
|
||
|
|
{
|
||
|
|
enum VibrationPattern
|
||
|
|
{
|
||
|
|
case success
|
||
|
|
case error
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
@available(iOS 13, *)
|
||
|
|
extension UIDevice
|
||
|
|
{
|
||
|
|
var isVibrationSupported: Bool {
|
||
|
|
return CHHapticEngine.capabilitiesForHardware().supportsHaptics
|
||
|
|
}
|
||
|
|
|
||
|
|
func vibrate(pattern: VibrationPattern)
|
||
|
|
{
|
||
|
|
guard self.isVibrationSupported else { return }
|
||
|
|
|
||
|
|
switch pattern
|
||
|
|
{
|
||
|
|
case .success: AudioServicesPlaySystemSound(.tryAgain)
|
||
|
|
case .error: AudioServicesPlaySystemSound(.cancelled)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|