Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/youdao #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions ios/Classes/SwiftVibrationPlugin.swift

This file was deleted.

17 changes: 17 additions & 0 deletions ios/Classes/Vibration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Vibration.h
// vibration
//
// Created by 车德超 on 2020/2/14.
//

#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>

NS_ASSUME_NONNULL_BEGIN

@interface Vibration : NSObject<FlutterPlugin>

@end

NS_ASSUME_NONNULL_END
44 changes: 44 additions & 0 deletions ios/Classes/Vibration.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Vibration.m
// vibration
//
// Created by 车德超 on 2020/2/14.
//

#import "Vibration.h"
#import <AudioToolbox/AudioToolbox.h>

@interface Vibration ()

@property (nonatomic, assign) bool isDevice;

@end

@implementation Vibration

+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"vibration"
binaryMessenger:[registrar messenger]];
Vibration* instance = [[Vibration alloc] init];
[registrar addMethodCallDelegate:instance channel:channel];
}

- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
self.isDevice = (TARGET_OS_SIMULATOR == 0);
if ([@"hasVibrator" isEqualToString:call.method]) {
result([[NSNumber alloc] initWithBool:self.isDevice]);
result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
} else if ([@"hasAmplitudeControl" isEqualToString:call.method]) {
result([[NSNumber alloc] initWithBool:self.isDevice]);
} else if ([@"vibrate" isEqualToString:call.method]) {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
result(nil);
}else if ([@"cancel" isEqualToString:call.method]) {
result(nil);
}else {
result(FlutterMethodNotImplemented);
}
}

@end
4 changes: 2 additions & 2 deletions ios/Classes/VibrationPlugin.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#import "VibrationPlugin.h"
#import <vibration/vibration-Swift.h>
#import "Vibration.h"

@implementation VibrationPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
[SwiftVibrationPlugin registerWithRegistrar:registrar];
[Vibration registerWithRegistrar:registrar];
}
@end