Browse Source

Merge pull request #1 from trestrantham/ios-speech-recognition

Add iOS speech recognition
Tres Trantham 7 years ago
parent
commit
1225500d7e

+ 2
- 1
RCTConvert+RNPStatus.h View File

25
     RNPTypeReminder,
25
     RNPTypeReminder,
26
     RNPTypeBluetooth,
26
     RNPTypeBluetooth,
27
     RNPTypeNotification,
27
     RNPTypeNotification,
28
-    RNPTypeBackgroundRefresh
28
+    RNPTypeBackgroundRefresh,
29
+    RNPTypeSpeechRecognition
29
 };
30
 };
30
 
31
 
31
 @interface RCTConvert (RNPStatus)
32
 @interface RCTConvert (RNPStatus)

+ 2
- 1
RCTConvert+RNPStatus.m View File

20
                                 @"reminder" : @(RNPTypeReminder),
20
                                 @"reminder" : @(RNPTypeReminder),
21
                                 @"bluetooth" : @(RNPTypeBluetooth),
21
                                 @"bluetooth" : @(RNPTypeBluetooth),
22
                                 @"notification" : @(RNPTypeNotification),
22
                                 @"notification" : @(RNPTypeNotification),
23
-                                @"backgroundRefresh": @(RNPTypeBackgroundRefresh)
23
+                                @"backgroundRefresh": @(RNPTypeBackgroundRefresh),
24
+                                @"speechRecognition": @(RNPTypeSpeechRecognition)
24
                                 }),
25
                                 }),
25
                                 RNPTypeUnknown, integerValue)
26
                                 RNPTypeUnknown, integerValue)
26
 
27
 

+ 1
- 0
ReactNativePermissions.js View File

16
 		'bluetooth',
16
 		'bluetooth',
17
 		'notification',
17
 		'notification',
18
 		'backgroundRefresh', 
18
 		'backgroundRefresh', 
19
+		'speechRecognition', 
19
 	],
20
 	],
20
 	android: [
21
 	android: [
21
 		'location',
22
 		'location',

+ 6
- 0
ReactNativePermissions.m View File

22
 #import "RNPPhoto.h"
22
 #import "RNPPhoto.h"
23
 #import "RNPContacts.h"
23
 #import "RNPContacts.h"
24
 #import "RNPBackgroundRefresh.h"
24
 #import "RNPBackgroundRefresh.h"
25
+#import "RNPSpeechRecognition.h"
25
 
26
 
26
 @interface ReactNativePermissions()
27
 @interface ReactNativePermissions()
27
 @property (strong, nonatomic) RNPLocation *locationMgr;
28
 @property (strong, nonatomic) RNPLocation *locationMgr;
102
         case RNPTypeBackgroundRefresh:
103
         case RNPTypeBackgroundRefresh:
103
             status = [RNPBackgroundRefresh getStatus];
104
             status = [RNPBackgroundRefresh getStatus];
104
             break;
105
             break;
106
+        case RNPTypeSpeechRecognition:
107
+            status = [RNPSpeechRecognition getStatus];
108
+            break;
105
         default:
109
         default:
106
             break;
110
             break;
107
     }
111
     }
132
             return [self requestBluetooth:resolve];
136
             return [self requestBluetooth:resolve];
133
         case RNPTypeNotification:
137
         case RNPTypeNotification:
134
             return [self requestNotification:json resolve:resolve];
138
             return [self requestNotification:json resolve:resolve];
139
+        case RNPTypeSpeechRecognition:
140
+            return [RNPSpeechRecognition request:resolve];
135
         default:
141
         default:
136
             break;
142
             break;
137
     }
143
     }

+ 6
- 1
ReactNativePermissions.xcodeproj/project.pbxproj View File

7
 	objects = {
7
 	objects = {
8
 
8
 
9
 /* Begin PBXBuildFile section */
9
 /* Begin PBXBuildFile section */
10
+		2894D7D21E25876700401A74 /* RNPSpeechRecognition.m in Sources */ = {isa = PBXBuildFile; fileRef = 2894D7D11E25876700401A74 /* RNPSpeechRecognition.m */; };
10
 		9D46283E1D34719100346A5B /* RNPAudioVideo.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D46282F1D34719100346A5B /* RNPAudioVideo.m */; };
11
 		9D46283E1D34719100346A5B /* RNPAudioVideo.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D46282F1D34719100346A5B /* RNPAudioVideo.m */; };
11
 		9D46283F1D34719100346A5B /* RNPBackgroundRefresh.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D4628311D34719100346A5B /* RNPBackgroundRefresh.m */; };
12
 		9D46283F1D34719100346A5B /* RNPBackgroundRefresh.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D4628311D34719100346A5B /* RNPBackgroundRefresh.m */; };
12
 		9D4628401D34719100346A5B /* RNPBluetooth.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D4628331D34719100346A5B /* RNPBluetooth.m */; };
13
 		9D4628401D34719100346A5B /* RNPBluetooth.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D4628331D34719100346A5B /* RNPBluetooth.m */; };
32
 /* End PBXCopyFilesBuildPhase section */
33
 /* End PBXCopyFilesBuildPhase section */
33
 
34
 
34
 /* Begin PBXFileReference section */
35
 /* Begin PBXFileReference section */
35
-		9D23B34F1C767B80008B4819 /* libReactNativePermissions.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libReactNativePermissions.a; sourceTree = BUILT_PRODUCTS_DIR; };
36
+		2894D7D01E25876700401A74 /* RNPSpeechRecognition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNPSpeechRecognition.h; path = permissions/RNPSpeechRecognition.h; sourceTree = SOURCE_ROOT; };
37
+		2894D7D11E25876700401A74 /* RNPSpeechRecognition.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNPSpeechRecognition.m; path = permissions/RNPSpeechRecognition.m; sourceTree = SOURCE_ROOT; };
36
 		9D46282E1D34719100346A5B /* RNPAudioVideo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNPAudioVideo.h; path = permissions/RNPAudioVideo.h; sourceTree = SOURCE_ROOT; };
38
 		9D46282E1D34719100346A5B /* RNPAudioVideo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNPAudioVideo.h; path = permissions/RNPAudioVideo.h; sourceTree = SOURCE_ROOT; };
37
 		9D46282F1D34719100346A5B /* RNPAudioVideo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNPAudioVideo.m; path = permissions/RNPAudioVideo.m; sourceTree = SOURCE_ROOT; };
39
 		9D46282F1D34719100346A5B /* RNPAudioVideo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNPAudioVideo.m; path = permissions/RNPAudioVideo.m; sourceTree = SOURCE_ROOT; };
38
 		9D4628301D34719100346A5B /* RNPBackgroundRefresh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNPBackgroundRefresh.h; path = permissions/RNPBackgroundRefresh.h; sourceTree = SOURCE_ROOT; };
40
 		9D4628301D34719100346A5B /* RNPBackgroundRefresh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNPBackgroundRefresh.h; path = permissions/RNPBackgroundRefresh.h; sourceTree = SOURCE_ROOT; };
97
 		9D4628091D33C1EC00346A5B /* permissions */ = {
99
 		9D4628091D33C1EC00346A5B /* permissions */ = {
98
 			isa = PBXGroup;
100
 			isa = PBXGroup;
99
 			children = (
101
 			children = (
102
+				2894D7D01E25876700401A74 /* RNPSpeechRecognition.h */,
103
+				2894D7D11E25876700401A74 /* RNPSpeechRecognition.m */,
100
 				9D46282E1D34719100346A5B /* RNPAudioVideo.h */,
104
 				9D46282E1D34719100346A5B /* RNPAudioVideo.h */,
101
 				9D46282F1D34719100346A5B /* RNPAudioVideo.m */,
105
 				9D46282F1D34719100346A5B /* RNPAudioVideo.m */,
102
 				9D4628301D34719100346A5B /* RNPBackgroundRefresh.h */,
106
 				9D4628301D34719100346A5B /* RNPBackgroundRefresh.h */,
175
 			files = (
179
 			files = (
176
 				9D46283F1D34719100346A5B /* RNPBackgroundRefresh.m in Sources */,
180
 				9D46283F1D34719100346A5B /* RNPBackgroundRefresh.m in Sources */,
177
 				9D4628451D34719100346A5B /* RNPPhoto.m in Sources */,
181
 				9D4628451D34719100346A5B /* RNPPhoto.m in Sources */,
182
+				2894D7D21E25876700401A74 /* RNPSpeechRecognition.m in Sources */,
178
 				9D4628431D34719100346A5B /* RNPLocation.m in Sources */,
183
 				9D4628431D34719100346A5B /* RNPLocation.m in Sources */,
179
 				9D46283E1D34719100346A5B /* RNPAudioVideo.m in Sources */,
184
 				9D46283E1D34719100346A5B /* RNPAudioVideo.m in Sources */,
180
 				9D4628401D34719100346A5B /* RNPBluetooth.m in Sources */,
185
 				9D4628401D34719100346A5B /* RNPBluetooth.m in Sources */,

+ 17
- 0
permissions/RNPSpeechRecognition.h View File

1
+//
2
+//  RNPSpeechRecognition.h
3
+//  ReactNativePermissions
4
+//
5
+//  Created by Tres Trantham on 01/10/17.
6
+//  Copyright © 2017 Tres Trantham. All rights reserved.
7
+//
8
+
9
+#import <Foundation/Foundation.h>
10
+#import "RCTConvert+RNPStatus.h"
11
+
12
+@interface RNPSpeechRecognition : NSObject
13
+
14
++ (NSString *)getStatus;
15
++ (void)request:(void (^)(NSString *))completionHandler;
16
+
17
+@end

+ 45
- 0
permissions/RNPSpeechRecognition.m View File

1
+//
2
+//  RNPSpeechRecognition.m
3
+//  ReactNativePermissions
4
+//
5
+//  Created by Tres Trantham on 01/10/17.
6
+//  Copyright © 2017 Tres Trantham. All rights reserved.
7
+//
8
+
9
+#import "RNPSpeechRecognition.h"
10
+
11
+#import <AVFoundation/AVFoundation.h>
12
+
13
+@implementation RNPSpeechRecognition
14
+
15
++ (NSString *)getStatus:(NSString *)type
16
+{
17
+
18
+  int status = [SFSpeechRecognizer authorizationStatus];
19
+
20
+  switch (status) {
21
+      case SFSpeechRecognizerAuthorizationStatusAuthorized:
22
+          return RNPStatusAuthorized;
23
+      case SFSpeechRecognizerAuthorizationStatusDenied:
24
+          return RNPStatusDenied;
25
+      case SFSpeechRecognizerAuthorizationStatusRestricted:
26
+          return RNPStatusRestricted;
27
+      default:
28
+          return RNPStatusUndetermined;
29
+  }
30
+}
31
+
32
++ (void)request:(void (^)(NSString *))completionHandler
33
+{
34
+    void (^handler)(void) =  ^(void) {
35
+        dispatch_async(dispatch_get_main_queue(), ^{
36
+            completionHandler([self.class getStatus]);
37
+        });
38
+    };
39
+
40
+    [SFSpeechRecognizer requestAuthorization:^(SFSpeechRecognizerAuthorizationStatus status) {
41
+        handler();
42
+    }];
43
+}
44
+
45
+@end