add flutter_vibrate

This commit is contained in:
2026-01-13 22:03:47 -08:00
parent a2af086126
commit 7eb3d100ac
89 changed files with 2213 additions and 0 deletions
@@ -0,0 +1,101 @@
import Flutter
import UIKit
import AudioToolbox
private let isDevice = TARGET_OS_SIMULATOR == 0
public class SwiftVibratePlugin: NSObject, FlutterPlugin {
public static func register(with registrar: FlutterPluginRegistrar) {
let channel = FlutterMethodChannel(name: "vibrate", binaryMessenger: registrar.messenger())
let instance = SwiftVibratePlugin()
registrar.addMethodCallDelegate(instance, channel: channel)
}
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
switch (call.method) {
case "canVibrate":
if isDevice {
result(true)
} else {
result(false)
}
case "vibrate":
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
// Feedback
case "impact":
if #available(iOS 10.0, *) {
let impact = UIImpactFeedbackGenerator()
impact.prepare()
impact.impactOccurred()
} else {
// Fallback on earlier versions
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
}
case "selection":
if #available(iOS 10.0, *) {
let selection = UISelectionFeedbackGenerator()
selection.prepare()
selection.selectionChanged()
} else {
// Fallback on earlier versions
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
}
case "success":
if #available(iOS 10.0, *) {
let notification = UINotificationFeedbackGenerator()
notification.prepare()
notification.notificationOccurred(.success)
} else {
// Fallback on earlier versions
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
}
case "warning":
if #available(iOS 10.0, *) {
let notification = UINotificationFeedbackGenerator()
notification.prepare()
notification.notificationOccurred(.warning)
} else {
// Fallback on earlier versions
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
}
case "error":
if #available(iOS 10.0, *) {
let notification = UINotificationFeedbackGenerator()
notification.prepare()
notification.notificationOccurred(.error)
} else {
// Fallback on earlier versions
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
}
case "heavy":
if #available(iOS 10.0, *) {
let generator = UIImpactFeedbackGenerator(style: .heavy)
generator.prepare()
generator.impactOccurred()
} else {
// Fallback on earlier versions
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
}
case "medium":
if #available(iOS 10.0, *) {
let generator = UIImpactFeedbackGenerator(style: .medium)
generator.prepare()
generator.impactOccurred()
} else {
// Fallback on earlier versions
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
}
case "light":
if #available(iOS 10.0, *) {
let generator = UIImpactFeedbackGenerator(style: .light)
generator.prepare()
generator.impactOccurred()
} else {
// Fallback on earlier versions
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
}
default:
result(FlutterMethodNotImplemented)
}
}
}
@@ -0,0 +1,4 @@
#import <Flutter/Flutter.h>
@interface VibratePlugin : NSObject<FlutterPlugin>
@end
@@ -0,0 +1,8 @@
#import "VibratePlugin.h"
#import <flutter_vibrate/flutter_vibrate-Swift.h>
@implementation VibratePlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
[SwiftVibratePlugin registerWithRegistrar:registrar];
}
@end