Skip to content

Commit 36b39ee

Browse files
author
Rory Pickering
authored
Merge branch 'master' into master
2 parents 637d665 + 72128a0 commit 36b39ee

File tree

9 files changed

+97
-2
lines changed

9 files changed

+97
-2
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ The current supported permissions are:
161161
| Background Refresh | `backgroundRefresh` | ✔️ ||
162162
| Speech Recognition | `speechRecognition` | ✔️ ||
163163
| mediaLibrary | `mediaLibrary` | ✔️ ||
164+
| Motion Activity | `motion` | ✔️ ||
164165
| Storage | `storage` | ❌️ ||
165166
| Phone Call | `callPhone` | ❌️ ||
166167
| Read SMS | `readSms` | ❌️ ||
@@ -242,7 +243,8 @@ So before submitting your app to the App Store, make sure that in your
242243
<string>Some description</string>
243244
<key>NSAppleMusicUsageDescription</key>
244245
<string>Some description</string>
245-
```
246+
<key>NSMotionUsageDescription</key>
247+
<string>Some description</string>
246248

247249
This is required because during the phase of processing in the App Store
248250
submission, the system detects that you app contains code to request the

example/ios/Example/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
<string>test</string>
5858
<key>NSSpeechRecognitionUsageDescription</key>
5959
<string>test</string>
60+
<key>NSMotionUsageDescription</key>
61+
<string>test</string>
6062
<key>UIBackgroundModes</key>
6163
<array>
6264
<string>bluetooth-peripheral</string>

ios/Permissions/RNPMotion.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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

ios/Permissions/RNPMotion.m

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

ios/RCTConvert+RNPStatus.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ typedef NS_ENUM(NSInteger, RNPType) {
3434
RNPTypeBackgroundRefresh,
3535
RNPTypeSpeechRecognition,
3636
RNPTypeMediaLibrary
37+
RNPTypeMotion
3738
};
3839

3940
@interface RCTConvert (RNPStatus)

ios/RCTConvert+RNPStatus.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ @implementation RCTConvert (RNPStatus)
2222
@"backgroundRefresh": @(RNPTypeBackgroundRefresh),
2323
@"speechRecognition": @(RNPTypeSpeechRecognition),
2424
@"mediaLibrary": @(RNPTypeMediaLibrary)
25+
@"motion": @(RNPTypeMotion)
2526
}),
2627
RNPTypeUnknown, integerValue)
2728

ios/ReactNativePermissions.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
#import "RNPBackgroundRefresh.h"
4545
#import "RNPSpeechRecognition.h"
4646
#import "RNPMediaLibrary.h"
47+
#import "RNPMotion.h"
48+
4749

4850
@interface ReactNativePermissions()
4951
@property (strong, nonatomic) RNPLocation *locationMgr;
@@ -148,6 +150,8 @@ - (dispatch_queue_t)methodQueue {
148150
break;
149151
case RNPTypeMediaLibrary:
150152
status = [RNPMediaLibrary getStatus];
153+
case RNPTypeMotion:
154+
status = [RNPMotion getStatus];
151155
break;
152156
default:
153157
break;
@@ -183,6 +187,8 @@ - (dispatch_queue_t)methodQueue {
183187
return [RNPSpeechRecognition request:resolve];
184188
case RNPTypeMediaLibrary:
185189
return [RNPMediaLibrary request:resolve];
190+
case RNPTypeMotion:
191+
return [RNPMotion request:resolve];
186192
default:
187193
break;
188194
}

ios/ReactNativePermissions.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
669582131FE441A8008596CD /* RNPAudioVideo.m in Sources */ = {isa = PBXBuildFile; fileRef = 669582071FE441A7008596CD /* RNPAudioVideo.m */; };
2121
669582141FE441A8008596CD /* RNPContacts.m in Sources */ = {isa = PBXBuildFile; fileRef = 669582081FE441A8008596CD /* RNPContacts.m */; };
2222
669582151FE441A8008596CD /* RNPEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 6695820A1FE441A8008596CD /* RNPEvent.m */; };
23+
D0AD62322000657000D89898 /* RNPMotion.m in Sources */ = {isa = PBXBuildFile; fileRef = D0AD62312000657000D89898 /* RNPMotion.m */; };
2324
/* End PBXBuildFile section */
2425

2526
/* Begin PBXCopyFilesBuildPhase section */
@@ -61,6 +62,8 @@
6162
6695820B1FE441A8008596CD /* RNPSpeechRecognition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPSpeechRecognition.h; sourceTree = "<group>"; };
6263
6695820C1FE441A8008596CD /* RNPNotification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNPNotification.h; sourceTree = "<group>"; };
6364
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>"; };
6467
/* End PBXFileReference section */
6568

6669
/* Begin PBXFrameworksBuildPhase section */
@@ -98,6 +101,8 @@
98101
669582081FE441A8008596CD /* RNPContacts.m */,
99102
669582061FE441A7008596CD /* RNPEvent.h */,
100103
6695820A1FE441A8008596CD /* RNPEvent.m */,
104+
D0AD62302000656F00D89898 /* RNPMotion.h */,
105+
D0AD62312000657000D89898 /* RNPMotion.m */,
101106
669582021FE441A7008596CD /* RNPLocation.h */,
102107
669581FE1FE441A7008596CD /* RNPLocation.m */,
103108
6695820C1FE441A8008596CD /* RNPNotification.h */,
@@ -197,6 +202,7 @@
197202
669582141FE441A8008596CD /* RNPContacts.m in Sources */,
198203
6695820D1FE441A8008596CD /* RNPSpeechRecognition.m in Sources */,
199204
669582131FE441A8008596CD /* RNPAudioVideo.m in Sources */,
205+
D0AD62322000657000D89898 /* RNPMotion.m in Sources */,
200206
669581F81FE4416B008596CD /* ReactNativePermissions.m in Sources */,
201207
669582121FE441A8008596CD /* RNPPhoto.m in Sources */,
202208
);

lib/permissions.ios.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ const permissionTypes = [
2020
'notification',
2121
'backgroundRefresh',
2222
'speechRecognition',
23-
'mediaLibrary'
23+
'mediaLibrary',
24+
'motion'
2425
]
2526

2627
const DEFAULTS = {

0 commit comments

Comments
 (0)