浏览代码

Merge branch 'master' into master

Rory Pickering 8 年之前
父节点
当前提交
36b39ee726

+ 3 - 1
README.md

@@ -161,6 +161,7 @@ The current supported permissions are:
 | Background Refresh | `backgroundRefresh` | ✔️  | ❌      |
 | Background Refresh | `backgroundRefresh` | ✔️  | ❌      |
 | Speech Recognition | `speechRecognition` | ✔️  | ❌      |
 | Speech Recognition | `speechRecognition` | ✔️  | ❌      |
 | mediaLibrary       | `mediaLibrary`      | ✔️  | ❌      |
 | mediaLibrary       | `mediaLibrary`      | ✔️  | ❌      |
+| Motion Activity    | `motion`            | ✔️  | ❌      |
 | Storage            | `storage`           | ❌️ | ✔       |
 | Storage            | `storage`           | ❌️ | ✔       |
 | Phone Call         | `callPhone`         | ❌️ | ✔       |
 | Phone Call         | `callPhone`         | ❌️ | ✔       |
 | Read SMS           | `readSms`           | ❌️ | ✔       |
 | Read SMS           | `readSms`           | ❌️ | ✔       |
@@ -242,7 +243,8 @@ So before submitting your app to the App Store, make sure that in your
 <string>Some description</string>
 <string>Some description</string>
 <key>NSAppleMusicUsageDescription</key>
 <key>NSAppleMusicUsageDescription</key>
 <string>Some description</string>
 <string>Some description</string>
-```
+<key>NSMotionUsageDescription</key>
+<string>Some description</string>
 
 
 This is required because during the phase of processing in the App Store
 This is required because during the phase of processing in the App Store
 submission, the system detects that you app contains code to request the
 submission, the system detects that you app contains code to request the

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

@@ -57,6 +57,8 @@
 	<string>test</string>
 	<string>test</string>
 	<key>NSSpeechRecognitionUsageDescription</key>
 	<key>NSSpeechRecognitionUsageDescription</key>
 	<string>test</string>
 	<string>test</string>
+	<key>NSMotionUsageDescription</key>
+	<string>test</string>
 	<key>UIBackgroundModes</key>
 	<key>UIBackgroundModes</key>
 	<array>
 	<array>
 		<string>bluetooth-peripheral</string>
 		<string>bluetooth-peripheral</string>

+ 14 - 0
ios/Permissions/RNPMotion.h

@@ -0,0 +1,14 @@
+//
+//  RNPMotion.h
+//  ReactNativePermissions
+//
+
+#import <Foundation/Foundation.h>
+#import "RCTConvert+RNPStatus.h"
+
+@interface RNPMotion : NSObject
+
++ (NSString *)getStatus;
++ (void)request:(void (^)(NSString *))completionHandler;
+
+@end

+ 62 - 0
ios/Permissions/RNPMotion.m

@@ -0,0 +1,62 @@
+//
+//  RNPMotion.m
+//  ReactNativePermissions
+//
+
+#import "RNPMotion.h"
+#import <CoreMotion/CoreMotion.h>
+
+@implementation RNPMotion
+
++ (NSString *)getStatus
+{
+    if (![CMMotionActivityManager isActivityAvailable]) {
+        return RNPStatusRestricted;
+    }
+    
+    if (@available(iOS 11.0, *)) {
+        CMAuthorizationStatus status = [CMMotionActivityManager authorizationStatus];
+        
+        switch (status) {
+            case CMAuthorizationStatusAuthorized:
+                return RNPStatusAuthorized;
+            case CMAuthorizationStatusDenied:
+                return RNPStatusDenied;
+            case CMAuthorizationStatusNotDetermined:
+                return RNPStatusUndetermined;
+            case CMAuthorizationStatusRestricted:
+                return RNPStatusRestricted;
+            default:
+                return RNPStatusUndetermined;
+        }
+    } else {
+        return RNPStatusRestricted;
+    }
+}
+
++ (void)request:(void (^)(NSString *))completionHandler
+{
+    __block NSString *status = [RNPMotion getStatus];
+    
+    if ([status isEqual: RNPStatusUndetermined]) {
+        __block CMMotionActivityManager *activityManager = [[CMMotionActivityManager alloc] init];
+        __block NSOperationQueue *motionActivityQueue = [[NSOperationQueue alloc] init];
+        [activityManager queryActivityStartingFromDate:[NSDate distantPast] toDate:[NSDate date] toQueue:motionActivityQueue withHandler:^(NSArray *activities, NSError *error) {
+            if (error) {
+                status = RNPStatusDenied;
+            } else if (activities || !error) {
+                status = RNPStatusAuthorized;
+            }
+            
+            dispatch_async(dispatch_get_main_queue(), ^{
+                completionHandler(status);
+            });
+            
+            activityManager = nil;
+            motionActivityQueue = nil;
+        }];
+    } else {
+        completionHandler(status);
+    }
+}
+@end

+ 1 - 0
ios/RCTConvert+RNPStatus.h

@@ -34,6 +34,7 @@ typedef NS_ENUM(NSInteger, RNPType) {
     RNPTypeBackgroundRefresh,
     RNPTypeBackgroundRefresh,
     RNPTypeSpeechRecognition,
     RNPTypeSpeechRecognition,
     RNPTypeMediaLibrary
     RNPTypeMediaLibrary
+    RNPTypeMotion
 };
 };
 
 
 @interface RCTConvert (RNPStatus)
 @interface RCTConvert (RNPStatus)

+ 1 - 0
ios/RCTConvert+RNPStatus.m

@@ -22,6 +22,7 @@ RCT_ENUM_CONVERTER(RNPType, (@{ @"location" : @(RNPTypeLocation),
                                 @"backgroundRefresh": @(RNPTypeBackgroundRefresh),
                                 @"backgroundRefresh": @(RNPTypeBackgroundRefresh),
                                 @"speechRecognition": @(RNPTypeSpeechRecognition),
                                 @"speechRecognition": @(RNPTypeSpeechRecognition),
                                 @"mediaLibrary": @(RNPTypeMediaLibrary)
                                 @"mediaLibrary": @(RNPTypeMediaLibrary)
+                                @"motion": @(RNPTypeMotion)
                                 }),
                                 }),
                                 RNPTypeUnknown, integerValue)
                                 RNPTypeUnknown, integerValue)
 
 

+ 6 - 0
ios/ReactNativePermissions.m

@@ -44,6 +44,8 @@
 #import "RNPBackgroundRefresh.h"
 #import "RNPBackgroundRefresh.h"
 #import "RNPSpeechRecognition.h"
 #import "RNPSpeechRecognition.h"
 #import "RNPMediaLibrary.h"
 #import "RNPMediaLibrary.h"
+#import "RNPMotion.h"
+
 
 
 @interface ReactNativePermissions()
 @interface ReactNativePermissions()
 @property (strong, nonatomic) RNPLocation *locationMgr;
 @property (strong, nonatomic) RNPLocation *locationMgr;
@@ -148,6 +150,8 @@ RCT_REMAP_METHOD(getPermissionStatus, getPermissionStatus:(RNPType)type json:(id
             break;
             break;
         case RNPTypeMediaLibrary:
         case RNPTypeMediaLibrary:
             status = [RNPMediaLibrary getStatus];
             status = [RNPMediaLibrary getStatus];
+        case RNPTypeMotion:
+            status = [RNPMotion getStatus];
             break;
             break;
         default:
         default:
             break;
             break;
@@ -183,6 +187,8 @@ RCT_REMAP_METHOD(requestPermission, permissionType:(RNPType)type json:(id)json r
             return [RNPSpeechRecognition request:resolve];
             return [RNPSpeechRecognition request:resolve];
         case RNPTypeMediaLibrary:
         case RNPTypeMediaLibrary:
             return [RNPMediaLibrary request:resolve];
             return [RNPMediaLibrary request:resolve];
+        case RNPTypeMotion:
+            return [RNPMotion request:resolve];
         default:
         default:
             break;
             break;
     }
     }

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

@@ -20,6 +20,7 @@
 		669582131FE441A8008596CD /* RNPAudioVideo.m in Sources */ = {isa = PBXBuildFile; fileRef = 669582071FE441A7008596CD /* RNPAudioVideo.m */; };
 		669582131FE441A8008596CD /* RNPAudioVideo.m in Sources */ = {isa = PBXBuildFile; fileRef = 669582071FE441A7008596CD /* RNPAudioVideo.m */; };
 		669582141FE441A8008596CD /* RNPContacts.m in Sources */ = {isa = PBXBuildFile; fileRef = 669582081FE441A8008596CD /* RNPContacts.m */; };
 		669582141FE441A8008596CD /* RNPContacts.m in Sources */ = {isa = PBXBuildFile; fileRef = 669582081FE441A8008596CD /* RNPContacts.m */; };
 		669582151FE441A8008596CD /* RNPEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6695820A1FE441A8008596CD /* RNPEvent.m */; };
 		669582151FE441A8008596CD /* RNPEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6695820A1FE441A8008596CD /* RNPEvent.m */; };
+		D0AD62322000657000D89898 /* RNPMotion.m in Sources */ = {isa = PBXBuildFile; fileRef = D0AD62312000657000D89898 /* RNPMotion.m */; };
 /* End PBXBuildFile section */
 /* End PBXBuildFile section */
 
 
 /* Begin PBXCopyFilesBuildPhase section */
 /* Begin PBXCopyFilesBuildPhase section */
@@ -61,6 +62,8 @@
 		6695820B1FE441A8008596CD /* RNPSpeechRecognition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPSpeechRecognition.h; sourceTree = "<group>"; };
 		6695820B1FE441A8008596CD /* RNPSpeechRecognition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPSpeechRecognition.h; sourceTree = "<group>"; };
 		6695820C1FE441A8008596CD /* RNPNotification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPNotification.h; sourceTree = "<group>"; };
 		6695820C1FE441A8008596CD /* RNPNotification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPNotification.h; sourceTree = "<group>"; };
 		9D23B34F1C767B80008B4819 /* libReactNativePermissions.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libReactNativePermissions.a; sourceTree = BUILT_PRODUCTS_DIR; };
 		9D23B34F1C767B80008B4819 /* libReactNativePermissions.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libReactNativePermissions.a; sourceTree = BUILT_PRODUCTS_DIR; };
+		D0AD62302000656F00D89898 /* RNPMotion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPMotion.h; sourceTree = "<group>"; };
+		D0AD62312000657000D89898 /* RNPMotion.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNPMotion.m; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 /* End PBXFileReference section */
 
 
 /* Begin PBXFrameworksBuildPhase section */
 /* Begin PBXFrameworksBuildPhase section */
@@ -98,6 +101,8 @@
 				669582081FE441A8008596CD /* RNPContacts.m */,
 				669582081FE441A8008596CD /* RNPContacts.m */,
 				669582061FE441A7008596CD /* RNPEvent.h */,
 				669582061FE441A7008596CD /* RNPEvent.h */,
 				6695820A1FE441A8008596CD /* RNPEvent.m */,
 				6695820A1FE441A8008596CD /* RNPEvent.m */,
+				D0AD62302000656F00D89898 /* RNPMotion.h */,
+				D0AD62312000657000D89898 /* RNPMotion.m */,
 				669582021FE441A7008596CD /* RNPLocation.h */,
 				669582021FE441A7008596CD /* RNPLocation.h */,
 				669581FE1FE441A7008596CD /* RNPLocation.m */,
 				669581FE1FE441A7008596CD /* RNPLocation.m */,
 				6695820C1FE441A8008596CD /* RNPNotification.h */,
 				6695820C1FE441A8008596CD /* RNPNotification.h */,
@@ -197,6 +202,7 @@
 				669582141FE441A8008596CD /* RNPContacts.m in Sources */,
 				669582141FE441A8008596CD /* RNPContacts.m in Sources */,
 				6695820D1FE441A8008596CD /* RNPSpeechRecognition.m in Sources */,
 				6695820D1FE441A8008596CD /* RNPSpeechRecognition.m in Sources */,
 				669582131FE441A8008596CD /* RNPAudioVideo.m in Sources */,
 				669582131FE441A8008596CD /* RNPAudioVideo.m in Sources */,
+				D0AD62322000657000D89898 /* RNPMotion.m in Sources */,
 				669581F81FE4416B008596CD /* ReactNativePermissions.m in Sources */,
 				669581F81FE4416B008596CD /* ReactNativePermissions.m in Sources */,
 				669582121FE441A8008596CD /* RNPPhoto.m in Sources */,
 				669582121FE441A8008596CD /* RNPPhoto.m in Sources */,
 			);
 			);

+ 2 - 1
lib/permissions.ios.js

@@ -20,7 +20,8 @@ const permissionTypes = [
   'notification',
   'notification',
   'backgroundRefresh',
   'backgroundRefresh',
   'speechRecognition',
   'speechRecognition',
-  'mediaLibrary'
+  'mediaLibrary',
+  'motion'
 ]
 ]
 
 
 const DEFAULTS = {
 const DEFAULTS = {