Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let generator = UINotificationFeedbackGenerator()
- generator.notificationOccurred(.success)
- import AudioToolbox
- private let isDevice = TARGET_OS_SIMULATOR == 0
- func vibrate() {
- if isDevice {
- AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
- }
- }
- //ATTENTION: This is a private API, if you use this lines of code your app will be rejected
- id tapticEngine = [[UIDevice currentDevice] performSelector:NSSelectorFromString(@"_tapticEngine") withObject:nil];
- [tapticEngine performSelector:NSSelectorFromString(@"actuateFeedback:") withObject:@(0)];
- - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
- {
- [super touchesMoved:touches withEvent:event];
- UITouch *touch = [touches anyObject];
- CGFloat maximumPossibleForce = touch.maximumPossibleForce;
- CGFloat force = touch.force;
- CGFloat normalizedForce = force/maximumPossibleForce;
- NSLog(@"Normalized force : %f", normalizedForce);
- if (normalizedForce > 0.75)
- {
- NSLog(@"Strong");
- // Vibrate device
- AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
- }
- else
- {
- NSLog(@"Weak");
- }
- }
- // Vibrate device
- NSTimer * vibrationTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(vibrateDevice) userInfo:nil repeats:YES];
- - (void) vibrateDevice
- {
- if(duration == 2) // duration is a public variable to count vibration duration
- {
- // Stop the device vibration
- [vibrationTimer invalidate];
- return;
- }
- duration++;
- AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
- }
- // 1, 2, 3
- let generator = UINotificationFeedbackGenerator()
- generator.notificationOccurred(.error)
- generator.notificationOccurred(.success)
- generator.notificationOccurred(.warning)
- // 4
- let generator = UIImpactFeedbackGenerator(style: .light)
- generator.impactOccurred()
- // 5
- let generator = UIImpactFeedbackGenerator(style: .medium)
- generator.impactOccurred()
- // 6
- let generator = UIImpactFeedbackGenerator(style: .heavy)
- generator.impactOccurred()
- // 7
- let generator = UISelectionFeedbackGenerator()
- generator.selectionChanged()
Add Comment
Please, Sign In to add comment