add flutter_vibrate
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
.idea/
|
||||
.vagrant/
|
||||
.sconsign.dblite
|
||||
.svn/
|
||||
|
||||
.DS_Store
|
||||
*.swp
|
||||
profile
|
||||
|
||||
DerivedData/
|
||||
build/
|
||||
GeneratedPluginRegistrant.h
|
||||
GeneratedPluginRegistrant.m
|
||||
|
||||
.generated/
|
||||
|
||||
*.pbxuser
|
||||
*.mode1v3
|
||||
*.mode2v3
|
||||
*.perspectivev3
|
||||
|
||||
!default.pbxuser
|
||||
!default.mode1v3
|
||||
!default.mode2v3
|
||||
!default.perspectivev3
|
||||
|
||||
xcuserdata
|
||||
|
||||
*.moved-aside
|
||||
|
||||
*.pyc
|
||||
*sync/
|
||||
Icon?
|
||||
.tags*
|
||||
|
||||
/Flutter/Generated.xcconfig
|
||||
@@ -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
|
||||
@@ -0,0 +1,21 @@
|
||||
#
|
||||
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
|
||||
#
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'flutter_vibrate'
|
||||
s.version = '0.0.1'
|
||||
s.summary = 'A new Flutter plugin.'
|
||||
s.description = <<-DESC
|
||||
A new Flutter plugin.
|
||||
DESC
|
||||
s.homepage = 'http://example.com'
|
||||
s.license = { :file => '../LICENSE' }
|
||||
s.author = { 'Your Company' => 'email@example.com' }
|
||||
s.source = { :path => '.' }
|
||||
s.source_files = 'Classes/**/*'
|
||||
s.public_header_files = 'Classes/**/*.h'
|
||||
s.dependency 'Flutter'
|
||||
s.swift_version = '5.0'
|
||||
s.ios.deployment_target = '8.0'
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user