Browse Source

Merge pull request #210 from peterlau/motion-permission-request-fixed

Motion permission request - fixed conflicts
Mathieu Acthernoene 7 years ago
parent
commit
1ad011d04e
No account linked to committer's email address

+ 3
- 0
README.md View File

160
 | Push Notifications | `notification`      | ✔️  | ❌      |
160
 | Push Notifications | `notification`      | ✔️  | ❌      |
161
 | Background Refresh | `backgroundRefresh` | ✔️  | ❌      |
161
 | Background Refresh | `backgroundRefresh` | ✔️  | ❌      |
162
 | Speech Recognition | `speechRecognition` | ✔️  | ❌      |
162
 | Speech Recognition | `speechRecognition` | ✔️  | ❌      |
163
+| Motion Activity    | `motion`            | ✔️  | ❌      |
163
 | Storage            | `storage`           | ❌️ | ✔       |
164
 | Storage            | `storage`           | ❌️ | ✔       |
164
 | Phone Call         | `callPhone`         | ❌️ | ✔       |
165
 | Phone Call         | `callPhone`         | ❌️ | ✔       |
165
 | Read SMS           | `readSms`           | ❌️ | ✔       |
166
 | Read SMS           | `readSms`           | ❌️ | ✔       |
238
 <string>Some description</string>
239
 <string>Some description</string>
239
 <key>NSSpeechRecognitionUsageDescription</key>
240
 <key>NSSpeechRecognitionUsageDescription</key>
240
 <string>Some description</string>
241
 <string>Some description</string>
242
+<key>NSMotionUsageDescription</key>
243
+<string>Some description</string>
241
 ```
244
 ```
242
 
245
 
243
 This is required because during the phase of processing in the App Store
246
 This is required because during the phase of processing in the App Store

+ 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

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

32
     RNPTypeBluetooth,
32
     RNPTypeBluetooth,
33
     RNPTypeNotification,
33
     RNPTypeNotification,
34
     RNPTypeBackgroundRefresh,
34
     RNPTypeBackgroundRefresh,
35
-    RNPTypeSpeechRecognition
35
+    RNPTypeSpeechRecognition,
36
+    RNPTypeMotion
36
 };
37
 };
37
 
38
 
38
 @interface RCTConvert (RNPStatus)
39
 @interface RCTConvert (RNPStatus)

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

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

+ 6
- 0
ios/ReactNativePermissions.m View File

43
 #import "RNPContacts.h"
43
 #import "RNPContacts.h"
44
 #import "RNPBackgroundRefresh.h"
44
 #import "RNPBackgroundRefresh.h"
45
 #import "RNPSpeechRecognition.h"
45
 #import "RNPSpeechRecognition.h"
46
+#import "RNPMotion.h"
46
 
47
 
47
 @interface ReactNativePermissions()
48
 @interface ReactNativePermissions()
48
 @property (strong, nonatomic) RNPLocation *locationMgr;
49
 @property (strong, nonatomic) RNPLocation *locationMgr;
145
         case RNPTypeSpeechRecognition:
146
         case RNPTypeSpeechRecognition:
146
             status = [RNPSpeechRecognition getStatus];
147
             status = [RNPSpeechRecognition getStatus];
147
             break;
148
             break;
149
+        case RNPTypeMotion:
150
+            status = [RNPMotion getStatus];
151
+            break;
148
         default:
152
         default:
149
             break;
153
             break;
150
     }
154
     }
177
             return [self requestNotification:json resolve:resolve];
181
             return [self requestNotification:json resolve:resolve];
178
         case RNPTypeSpeechRecognition:
182
         case RNPTypeSpeechRecognition:
179
             return [RNPSpeechRecognition request:resolve];
183
             return [RNPSpeechRecognition request:resolve];
184
+        case RNPTypeMotion:
185
+            return [RNPMotion request:resolve];
180
         default:
186
         default:
181
             break;
187
             break;
182
     }
188
     }

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

18
 		669582131FE441A8008596CD /* RNPAudioVideo.m in Sources */ = {isa = PBXBuildFile; fileRef = 669582071FE441A7008596CD /* RNPAudioVideo.m */; };
18
 		669582131FE441A8008596CD /* RNPAudioVideo.m in Sources */ = {isa = PBXBuildFile; fileRef = 669582071FE441A7008596CD /* RNPAudioVideo.m */; };
19
 		669582141FE441A8008596CD /* RNPContacts.m in Sources */ = {isa = PBXBuildFile; fileRef = 669582081FE441A8008596CD /* RNPContacts.m */; };
19
 		669582141FE441A8008596CD /* RNPContacts.m in Sources */ = {isa = PBXBuildFile; fileRef = 669582081FE441A8008596CD /* RNPContacts.m */; };
20
 		669582151FE441A8008596CD /* RNPEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6695820A1FE441A8008596CD /* RNPEvent.m */; };
20
 		669582151FE441A8008596CD /* RNPEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6695820A1FE441A8008596CD /* RNPEvent.m */; };
21
+		D0AD62322000657000D89898 /* RNPMotion.m in Sources */ = {isa = PBXBuildFile; fileRef = D0AD62312000657000D89898 /* RNPMotion.m */; };
21
 /* End PBXBuildFile section */
22
 /* End PBXBuildFile section */
22
 
23
 
23
 /* Begin PBXCopyFilesBuildPhase section */
24
 /* Begin PBXCopyFilesBuildPhase section */
56
 		6695820B1FE441A8008596CD /* RNPSpeechRecognition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPSpeechRecognition.h; sourceTree = "<group>"; };
57
 		6695820B1FE441A8008596CD /* RNPSpeechRecognition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPSpeechRecognition.h; sourceTree = "<group>"; };
57
 		6695820C1FE441A8008596CD /* RNPNotification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPNotification.h; sourceTree = "<group>"; };
58
 		6695820C1FE441A8008596CD /* RNPNotification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPNotification.h; sourceTree = "<group>"; };
58
 		9D23B34F1C767B80008B4819 /* libReactNativePermissions.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libReactNativePermissions.a; sourceTree = BUILT_PRODUCTS_DIR; };
59
 		9D23B34F1C767B80008B4819 /* libReactNativePermissions.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libReactNativePermissions.a; sourceTree = BUILT_PRODUCTS_DIR; };
60
+		D0AD62302000656F00D89898 /* RNPMotion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPMotion.h; sourceTree = "<group>"; };
61
+		D0AD62312000657000D89898 /* RNPMotion.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNPMotion.m; sourceTree = "<group>"; };
59
 /* End PBXFileReference section */
62
 /* End PBXFileReference section */
60
 
63
 
61
 /* Begin PBXFrameworksBuildPhase section */
64
 /* Begin PBXFrameworksBuildPhase section */
82
 				669582081FE441A8008596CD /* RNPContacts.m */,
85
 				669582081FE441A8008596CD /* RNPContacts.m */,
83
 				669582061FE441A7008596CD /* RNPEvent.h */,
86
 				669582061FE441A7008596CD /* RNPEvent.h */,
84
 				6695820A1FE441A8008596CD /* RNPEvent.m */,
87
 				6695820A1FE441A8008596CD /* RNPEvent.m */,
88
+				D0AD62302000656F00D89898 /* RNPMotion.h */,
89
+				D0AD62312000657000D89898 /* RNPMotion.m */,
85
 				669582021FE441A7008596CD /* RNPLocation.h */,
90
 				669582021FE441A7008596CD /* RNPLocation.h */,
86
 				669581FE1FE441A7008596CD /* RNPLocation.m */,
91
 				669581FE1FE441A7008596CD /* RNPLocation.m */,
87
 				6695820C1FE441A8008596CD /* RNPNotification.h */,
92
 				6695820C1FE441A8008596CD /* RNPNotification.h */,
179
 				669582141FE441A8008596CD /* RNPContacts.m in Sources */,
184
 				669582141FE441A8008596CD /* RNPContacts.m in Sources */,
180
 				6695820D1FE441A8008596CD /* RNPSpeechRecognition.m in Sources */,
185
 				6695820D1FE441A8008596CD /* RNPSpeechRecognition.m in Sources */,
181
 				669582131FE441A8008596CD /* RNPAudioVideo.m in Sources */,
186
 				669582131FE441A8008596CD /* RNPAudioVideo.m in Sources */,
187
+				D0AD62322000657000D89898 /* RNPMotion.m in Sources */,
182
 				669581F81FE4416B008596CD /* ReactNativePermissions.m in Sources */,
188
 				669581F81FE4416B008596CD /* ReactNativePermissions.m in Sources */,
183
 				669582121FE441A8008596CD /* RNPPhoto.m in Sources */,
189
 				669582121FE441A8008596CD /* RNPPhoto.m in Sources */,
184
 			);
190
 			);

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

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