Guest User

Untitled

a guest
Nov 20th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. let generator = UINotificationFeedbackGenerator()
  2. generator.notificationOccurred(.success)
  3.  
  4. import AudioToolbox
  5.  
  6. private let isDevice = TARGET_OS_SIMULATOR == 0
  7.  
  8. func vibrate() {
  9. if isDevice {
  10. AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
  11. }
  12. }
  13.  
  14. //ATTENTION: This is a private API, if you use this lines of code your app will be rejected
  15.  
  16. id tapticEngine = [[UIDevice currentDevice] performSelector:NSSelectorFromString(@"_tapticEngine") withObject:nil];
  17. [tapticEngine performSelector:NSSelectorFromString(@"actuateFeedback:") withObject:@(0)];
  18.  
  19. - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
  20. {
  21. [super touchesMoved:touches withEvent:event];
  22.  
  23. UITouch *touch = [touches anyObject];
  24.  
  25. CGFloat maximumPossibleForce = touch.maximumPossibleForce;
  26. CGFloat force = touch.force;
  27. CGFloat normalizedForce = force/maximumPossibleForce;
  28. NSLog(@"Normalized force : %f", normalizedForce);
  29.  
  30. if (normalizedForce > 0.75)
  31. {
  32. NSLog(@"Strong");
  33. // Vibrate device
  34. AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
  35. }
  36. else
  37. {
  38. NSLog(@"Weak");
  39. }
  40. }
  41.  
  42. // Vibrate device
  43. NSTimer * vibrationTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(vibrateDevice) userInfo:nil repeats:YES];
  44.  
  45.  
  46. - (void) vibrateDevice
  47. {
  48. if(duration == 2) // duration is a public variable to count vibration duration
  49. {
  50. // Stop the device vibration
  51. [vibrationTimer invalidate];
  52. return;
  53. }
  54.  
  55. duration++;
  56. AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
  57. }
  58.  
  59. // 1, 2, 3
  60. let generator = UINotificationFeedbackGenerator()
  61. generator.notificationOccurred(.error)
  62. generator.notificationOccurred(.success)
  63. generator.notificationOccurred(.warning)
  64.  
  65. // 4
  66. let generator = UIImpactFeedbackGenerator(style: .light)
  67. generator.impactOccurred()
  68.  
  69. // 5
  70. let generator = UIImpactFeedbackGenerator(style: .medium)
  71. generator.impactOccurred()
  72.  
  73. // 6
  74. let generator = UIImpactFeedbackGenerator(style: .heavy)
  75. generator.impactOccurred()
  76.  
  77. // 7
  78. let generator = UISelectionFeedbackGenerator()
  79. generator.selectionChanged()
Add Comment
Please, Sign In to add comment