Browse Source

Merge branch 'master' into master

Rory Pickering 6 years ago
parent
commit
36b39ee726
No account linked to committer's email address

+ 3
- 1
README.md View File

161
 | Background Refresh | `backgroundRefresh` | ✔️  | ❌      |
161
 | Background Refresh | `backgroundRefresh` | ✔️  | ❌      |
162
 | Speech Recognition | `speechRecognition` | ✔️  | ❌      |
162
 | Speech Recognition | `speechRecognition` | ✔️  | ❌      |
163
 | mediaLibrary       | `mediaLibrary`      | ✔️  | ❌      |
163
 | mediaLibrary       | `mediaLibrary`      | ✔️  | ❌      |
164
+| Motion Activity    | `motion`            | ✔️  | ❌      |
164
 | Storage            | `storage`           | ❌️ | ✔       |
165
 | Storage            | `storage`           | ❌️ | ✔       |
165
 | Phone Call         | `callPhone`         | ❌️ | ✔       |
166
 | Phone Call         | `callPhone`         | ❌️ | ✔       |
166
 | Read SMS           | `readSms`           | ❌️ | ✔       |
167
 | Read SMS           | `readSms`           | ❌️ | ✔       |
242
 <string>Some description</string>
243
 <string>Some description</string>
243
 <key>NSAppleMusicUsageDescription</key>
244
 <key>NSAppleMusicUsageDescription</key>
244
 <string>Some description</string>
245
 <string>Some description</string>
245
-```
246
+<key>NSMotionUsageDescription</key>
247
+<string>Some description</string>
246
 
248
 
247
 This is required because during the phase of processing in the App Store
249
 This is required because during the phase of processing in the App Store
248
 submission, the system detects that you app contains code to request the
250
 submission, the system detects that you app contains code to request the

+ 2
- 0
example/ios/Example/Info.plist View File

57
 	<string>test</string>
57
 	<string>test</string>
58
 	<key>NSSpeechRecognitionUsageDescription</key>
58
 	<key>NSSpeechRecognitionUsageDescription</key>
59
 	<string>test</string>
59
 	<string>test</string>
60
+	<key>NSMotionUsageDescription</key>
61
+	<string>test</string>
60
 	<key>UIBackgroundModes</key>
62
 	<key>UIBackgroundModes</key>
61
 	<array>
63
 	<array>
62
 		<string>bluetooth-peripheral</string>
64
 		<string>bluetooth-peripheral</string>

+ 14
- 0
ios/Permissions/RNPMotion.h View File

1
+//
2
+//  RNPMotion.h
3
+//  ReactNativePermissions
4
+//
5
+
6
+#import <Foundation/Foundation.h>
7
+#import "RCTConvert+RNPStatus.h"
8
+
9
+@interface RNPMotion : NSObject
10
+
11
++ (NSString *)getStatus;
12
++ (void)request:(void (^)(NSString *))completionHandler;
13
+
14
+@end

+ 62
- 0
ios/Permissions/RNPMotion.m View File

1
+//
2
+//  RNPMotion.m
3
+//  ReactNativePermissions
4
+//
5
+
6
+#import "RNPMotion.h"
7
+#import <CoreMotion/CoreMotion.h>
8
+
9
+@implementation RNPMotion
10
+
11
++ (NSString *)getStatus
12
+{
13
+    if (![CMMotionActivityManager isActivityAvailable]) {
14
+        return RNPStatusRestricted;
15
+    }
16
+    
17
+    if (@available(iOS 11.0, *)) {
18
+        CMAuthorizationStatus status = [CMMotionActivityManager authorizationStatus];
19
+        
20
+        switch (status) {
21
+            case CMAuthorizationStatusAuthorized:
22
+                return RNPStatusAuthorized;
23
+            case CMAuthorizationStatusDenied:
24
+                return RNPStatusDenied;
25
+            case CMAuthorizationStatusNotDetermined:
26
+                return RNPStatusUndetermined;
27
+            case CMAuthorizationStatusRestricted:
28
+                return RNPStatusRestricted;
29
+            default:
30
+                return RNPStatusUndetermined;
31
+        }
32
+    } else {
33
+        return RNPStatusRestricted;
34
+    }
35
+}
36
+
37
++ (void)request:(void (^)(NSString *))completionHandler
38
+{
39
+    __block NSString *status = [RNPMotion getStatus];
40
+    
41
+    if ([status isEqual: RNPStatusUndetermined]) {
42
+        __block CMMotionActivityManager *activityManager = [[CMMotionActivityManager alloc] init];
43
+        __block NSOperationQueue *motionActivityQueue = [[NSOperationQueue alloc] init];
44
+        [activityManager queryActivityStartingFromDate:[NSDate distantPast] toDate:[NSDate date] toQueue:motionActivityQueue withHandler:^(NSArray *activities, NSError *error) {
45
+            if (error) {
46
+                status = RNPStatusDenied;
47
+            } else if (activities || !error) {
48
+                status = RNPStatusAuthorized;
49
+            }
50
+            
51
+            dispatch_async(dispatch_get_main_queue(), ^{
52
+                completionHandler(status);
53
+            });
54
+            
55
+            activityManager = nil;
56
+            motionActivityQueue = nil;
57
+        }];
58
+    } else {
59
+        completionHandler(status);
60
+    }
61
+}
62
+@end

+ 1
- 0
ios/RCTConvert+RNPStatus.h View File

34
     RNPTypeBackgroundRefresh,
34
     RNPTypeBackgroundRefresh,
35
     RNPTypeSpeechRecognition,
35
     RNPTypeSpeechRecognition,
36
     RNPTypeMediaLibrary
36
     RNPTypeMediaLibrary
37
+    RNPTypeMotion
37
 };
38
 };
38
 
39
 
39
 @interface RCTConvert (RNPStatus)
40
 @interface RCTConvert (RNPStatus)

+ 1
- 0
ios/RCTConvert+RNPStatus.m View File

22
                                 @"backgroundRefresh": @(RNPTypeBackgroundRefresh),
22
                                 @"backgroundRefresh": @(RNPTypeBackgroundRefresh),
23
                                 @"speechRecognition": @(RNPTypeSpeechRecognition),
23
                                 @"speechRecognition": @(RNPTypeSpeechRecognition),
24
                                 @"mediaLibrary": @(RNPTypeMediaLibrary)
24
                                 @"mediaLibrary": @(RNPTypeMediaLibrary)
25
+                                @"motion": @(RNPTypeMotion)
25
                                 }),
26
                                 }),
26
                                 RNPTypeUnknown, integerValue)
27
                                 RNPTypeUnknown, integerValue)
27
 
28
 

+ 6
- 0
ios/ReactNativePermissions.m View File

44
 #import "RNPBackgroundRefresh.h"
44
 #import "RNPBackgroundRefresh.h"
45
 #import "RNPSpeechRecognition.h"
45
 #import "RNPSpeechRecognition.h"
46
 #import "RNPMediaLibrary.h"
46
 #import "RNPMediaLibrary.h"
47
+#import "RNPMotion.h"
48
+
47
 
49
 
48
 @interface ReactNativePermissions()
50
 @interface ReactNativePermissions()
49
 @property (strong, nonatomic) RNPLocation *locationMgr;
51
 @property (strong, nonatomic) RNPLocation *locationMgr;
148
             break;
150
             break;
149
         case RNPTypeMediaLibrary:
151
         case RNPTypeMediaLibrary:
150
             status = [RNPMediaLibrary getStatus];
152
             status = [RNPMediaLibrary getStatus];
153
+        case RNPTypeMotion:
154
+            status = [RNPMotion getStatus];
151
             break;
155
             break;
152
         default:
156
         default:
153
             break;
157
             break;
183
             return [RNPSpeechRecognition request:resolve];
187
             return [RNPSpeechRecognition request:resolve];
184
         case RNPTypeMediaLibrary:
188
         case RNPTypeMediaLibrary:
185
             return [RNPMediaLibrary request:resolve];
189
             return [RNPMediaLibrary request:resolve];
190
+        case RNPTypeMotion:
191
+            return [RNPMotion request:resolve];
186
         default:
192
         default:
187
             break;
193
             break;
188
     }
194
     }

+ 6
- 0
ios/ReactNativePermissions.xcodeproj/project.pbxproj View File

20
 		669582131FE441A8008596CD /* RNPAudioVideo.m in Sources */ = {isa = PBXBuildFile; fileRef = 669582071FE441A7008596CD /* RNPAudioVideo.m */; };
20
 		669582131FE441A8008596CD /* RNPAudioVideo.m in Sources */ = {isa = PBXBuildFile; fileRef = 669582071FE441A7008596CD /* RNPAudioVideo.m */; };
21
 		669582141FE441A8008596CD /* RNPContacts.m in Sources */ = {isa = PBXBuildFile; fileRef = 669582081FE441A8008596CD /* RNPContacts.m */; };
21
 		669582141FE441A8008596CD /* RNPContacts.m in Sources */ = {isa = PBXBuildFile; fileRef = 669582081FE441A8008596CD /* RNPContacts.m */; };
22
 		669582151FE441A8008596CD /* RNPEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6695820A1FE441A8008596CD /* RNPEvent.m */; };
22
 		669582151FE441A8008596CD /* RNPEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6695820A1FE441A8008596CD /* RNPEvent.m */; };
23
+		D0AD62322000657000D89898 /* RNPMotion.m in Sources */ = {isa = PBXBuildFile; fileRef = D0AD62312000657000D89898 /* RNPMotion.m */; };
23
 /* End PBXBuildFile section */
24
 /* End PBXBuildFile section */
24
 
25
 
25
 /* Begin PBXCopyFilesBuildPhase section */
26
 /* Begin PBXCopyFilesBuildPhase section */
61
 		6695820B1FE441A8008596CD /* RNPSpeechRecognition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPSpeechRecognition.h; sourceTree = "<group>"; };
62
 		6695820B1FE441A8008596CD /* RNPSpeechRecognition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPSpeechRecognition.h; sourceTree = "<group>"; };
62
 		6695820C1FE441A8008596CD /* RNPNotification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPNotification.h; sourceTree = "<group>"; };
63
 		6695820C1FE441A8008596CD /* RNPNotification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPNotification.h; sourceTree = "<group>"; };
63
 		9D23B34F1C767B80008B4819 /* libReactNativePermissions.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libReactNativePermissions.a; sourceTree = BUILT_PRODUCTS_DIR; };
64
 		9D23B34F1C767B80008B4819 /* libReactNativePermissions.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libReactNativePermissions.a; sourceTree = BUILT_PRODUCTS_DIR; };
65
+		D0AD62302000656F00D89898 /* RNPMotion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPMotion.h; sourceTree = "<group>"; };
66
+		D0AD62312000657000D89898 /* RNPMotion.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNPMotion.m; sourceTree = "<group>"; };
64
 /* End PBXFileReference section */
67
 /* End PBXFileReference section */
65
 
68
 
66
 /* Begin PBXFrameworksBuildPhase section */
69
 /* Begin PBXFrameworksBuildPhase section */
98
 				669582081FE441A8008596CD /* RNPContacts.m */,
101
 				669582081FE441A8008596CD /* RNPContacts.m */,
99
 				669582061FE441A7008596CD /* RNPEvent.h */,
102
 				669582061FE441A7008596CD /* RNPEvent.h */,
100
 				6695820A1FE441A8008596CD /* RNPEvent.m */,
103
 				6695820A1FE441A8008596CD /* RNPEvent.m */,
104
+				D0AD62302000656F00D89898 /* RNPMotion.h */,
105
+				D0AD62312000657000D89898 /* RNPMotion.m */,
101
 				669582021FE441A7008596CD /* RNPLocation.h */,
106
 				669582021FE441A7008596CD /* RNPLocation.h */,
102
 				669581FE1FE441A7008596CD /* RNPLocation.m */,
107
 				669581FE1FE441A7008596CD /* RNPLocation.m */,
103
 				6695820C1FE441A8008596CD /* RNPNotification.h */,
108
 				6695820C1FE441A8008596CD /* RNPNotification.h */,
197
 				669582141FE441A8008596CD /* RNPContacts.m in Sources */,
202
 				669582141FE441A8008596CD /* RNPContacts.m in Sources */,
198
 				6695820D1FE441A8008596CD /* RNPSpeechRecognition.m in Sources */,
203
 				6695820D1FE441A8008596CD /* RNPSpeechRecognition.m in Sources */,
199
 				669582131FE441A8008596CD /* RNPAudioVideo.m in Sources */,
204
 				669582131FE441A8008596CD /* RNPAudioVideo.m in Sources */,
205
+				D0AD62322000657000D89898 /* RNPMotion.m in Sources */,
200
 				669581F81FE4416B008596CD /* ReactNativePermissions.m in Sources */,
206
 				669581F81FE4416B008596CD /* ReactNativePermissions.m in Sources */,
201
 				669582121FE441A8008596CD /* RNPPhoto.m in Sources */,
207
 				669582121FE441A8008596CD /* RNPPhoto.m in Sources */,
202
 			);
208
 			);

+ 2
- 1
lib/permissions.ios.js View File

20
   'notification',
20
   'notification',
21
   'backgroundRefresh',
21
   'backgroundRefresh',
22
   'speechRecognition',
22
   'speechRecognition',
23
-  'mediaLibrary'
23
+  'mediaLibrary',
24
+  'motion'
24
 ]
25
 ]
25
 
26
 
26
 const DEFAULTS = {
27
 const DEFAULTS = {