SendsmsPlugin.m
1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#import "SendsmsPlugin.h"
@implementation SendsmsPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"sendsms"
binaryMessenger:[registrar messenger]];
SendsmsPlugin* instance = [[SendsmsPlugin alloc] init];
[registrar addMethodCallDelegate:instance channel:channel];
}
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
if ([@"getPlatformVersion" isEqualToString:call.method]) {
result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
}else if([@"sendSMS" isEqualToString:call.method]){
NSString *phone = call.arguments[@"phoneNumber"];
NSString *content = call.arguments[@"message"];
// 短信号码可以为空
NSString *urlStr = [NSString stringWithFormat:@"sms://%@&body=%@", phone, content];
// 对中文进行编码 不进行中文编码,可能到时短信内容为null
urlStr = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
NSURL *url = [NSURL URLWithString:urlStr];
if (@available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
} else {
[[UIApplication sharedApplication] openURL:url];
}
}else if([@"getPermission" isEqualToString:call.method]) {
// result(true);
}else if([@"hasPermission" isEqualToString:call.method]){
// result(true);
}
else {
result(FlutterMethodNotImplemented);
}
}
@end