Skip to content

Commit 6e53aad

Browse files
authored
Merge pull request #211 from rory-pickering/master
Ability to query mediaLibrary on ios
2 parents 72128a0 + 36b39ee commit 6e53aad

File tree

8 files changed

+90
-2
lines changed

8 files changed

+90
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ The current supported permissions are:
160160
| Push Notifications | `notification` | ✔️ ||
161161
| Background Refresh | `backgroundRefresh` | ✔️ ||
162162
| Speech Recognition | `speechRecognition` | ✔️ ||
163+
| mediaLibrary | `mediaLibrary` | ✔️ ||
163164
| Motion Activity | `motion` | ✔️ ||
164165
| Storage | `storage` | ❌️ ||
165166
| Phone Call | `callPhone` | ❌️ ||
@@ -187,6 +188,7 @@ The current supported permissions are:
187188
* Permission type `notification` accepts a second parameter for `request()`. The
188189
second parameter is an array with the desired alert types. Any combination of
189190
`alert`, `badge` and `sound` (default requests all three).
191+
* If you are not requesting mediaLibrary then you can remove MediaPlayer.framework from the xcode project
190192

191193
```js
192194
// example
@@ -239,9 +241,10 @@ So before submitting your app to the App Store, make sure that in your
239241
<string>Some description</string>
240242
<key>NSSpeechRecognitionUsageDescription</key>
241243
<string>Some description</string>
244+
<key>NSAppleMusicUsageDescription</key>
245+
<string>Some description</string>
242246
<key>NSMotionUsageDescription</key>
243247
<string>Some description</string>
244-
```
245248

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

ios/Permissions/RNPMediaLibrary.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// RNPMediaLibrary.h
3+
// ReactNativePermissions
4+
//
5+
// Created by Yonah Forst on 11/07/16.
6+
// Copyright © 2016 Yonah Forst. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "RCTConvert+RNPStatus.h"
11+
12+
@interface RNPMediaLibrary : NSObject
13+
14+
+ (NSString *)getStatus;
15+
+ (void)request:(void (^)(NSString *))completionHandler;
16+
17+
@end

ios/Permissions/RNPMediaLibrary.m

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// RNPPhoto.m
3+
// ReactNativePermissions
4+
//
5+
// Created by Yonah Forst on 11/07/16.
6+
// Copyright © 2016 Yonah Forst. All rights reserved.
7+
//
8+
9+
#import "RNPMediaLibrary.h"
10+
#import <MediaPlayer/MediaPlayer.h>
11+
12+
@implementation RNPMediaLibrary
13+
14+
+ (NSString *)getStatus
15+
{
16+
int status = [MPMediaLibrary authorizationStatus];
17+
switch (status) {
18+
case MPMediaLibraryAuthorizationStatusAuthorized:
19+
return RNPStatusAuthorized;
20+
case MPMediaLibraryAuthorizationStatusDenied:
21+
return RNPStatusDenied;
22+
case MPMediaLibraryAuthorizationStatusRestricted:
23+
return RNPStatusRestricted;
24+
default:
25+
return RNPStatusUndetermined;
26+
}
27+
}
28+
29+
+ (void)request:(void (^)(NSString *))completionHandler
30+
{
31+
void (^handler)(void) = ^(void) {
32+
dispatch_async(dispatch_get_main_queue(), ^{
33+
completionHandler([self.class getStatus]);
34+
});
35+
};
36+
37+
[MPMediaLibrary requestAuthorization:^(MPMediaLibraryAuthorizationStatus status){
38+
handler();
39+
}];
40+
}
41+
@end

ios/RCTConvert+RNPStatus.h

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

ios/RCTConvert+RNPStatus.m

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

ios/ReactNativePermissions.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@
4343
#import "RNPContacts.h"
4444
#import "RNPBackgroundRefresh.h"
4545
#import "RNPSpeechRecognition.h"
46+
#import "RNPMediaLibrary.h"
4647
#import "RNPMotion.h"
4748

49+
4850
@interface ReactNativePermissions()
4951
@property (strong, nonatomic) RNPLocation *locationMgr;
5052
@property (strong, nonatomic) RNPNotification *notificationMgr;
@@ -146,6 +148,8 @@ - (dispatch_queue_t)methodQueue {
146148
case RNPTypeSpeechRecognition:
147149
status = [RNPSpeechRecognition getStatus];
148150
break;
151+
case RNPTypeMediaLibrary:
152+
status = [RNPMediaLibrary getStatus];
149153
case RNPTypeMotion:
150154
status = [RNPMotion getStatus];
151155
break;
@@ -181,6 +185,8 @@ - (dispatch_queue_t)methodQueue {
181185
return [self requestNotification:json resolve:resolve];
182186
case RNPTypeSpeechRecognition:
183187
return [RNPSpeechRecognition request:resolve];
188+
case RNPTypeMediaLibrary:
189+
return [RNPMediaLibrary request:resolve];
184190
case RNPTypeMotion:
185191
return [RNPMotion request:resolve];
186192
default:

ios/ReactNativePermissions.xcodeproj/project.pbxproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
488FE29C200BC8A100E05AB0 /* RNPMediaLibrary.m in Sources */ = {isa = PBXBuildFile; fileRef = 488FE29B200BC8A100E05AB0 /* RNPMediaLibrary.m */; };
11+
488FE2A2200BCED100E05AB0 /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 488FE2A1200BCEC900E05AB0 /* MediaPlayer.framework */; };
1012
669581F71FE4416B008596CD /* RCTConvert+RNPStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 669581F41FE4416B008596CD /* RCTConvert+RNPStatus.m */; };
1113
669581F81FE4416B008596CD /* ReactNativePermissions.m in Sources */ = {isa = PBXBuildFile; fileRef = 669581F51FE4416B008596CD /* ReactNativePermissions.m */; };
1214
6695820D1FE441A8008596CD /* RNPSpeechRecognition.m in Sources */ = {isa = PBXBuildFile; fileRef = 669581FD1FE441A7008596CD /* RNPSpeechRecognition.m */; };
@@ -34,6 +36,9 @@
3436
/* End PBXCopyFilesBuildPhase section */
3537

3638
/* Begin PBXFileReference section */
39+
488FE29B200BC8A100E05AB0 /* RNPMediaLibrary.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNPMediaLibrary.m; sourceTree = "<group>"; };
40+
488FE29D200BC8D200E05AB0 /* RNPMediaLibrary.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNPMediaLibrary.h; sourceTree = "<group>"; };
41+
488FE2A1200BCEC900E05AB0 /* MediaPlayer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MediaPlayer.framework; path = System/Library/Frameworks/MediaPlayer.framework; sourceTree = SDKROOT; };
3742
669581F31FE4416B008596CD /* ReactNativePermissions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReactNativePermissions.h; sourceTree = "<group>"; };
3843
669581F41FE4416B008596CD /* RCTConvert+RNPStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+RNPStatus.m"; sourceTree = "<group>"; };
3944
669581F51FE4416B008596CD /* ReactNativePermissions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReactNativePermissions.m; sourceTree = "<group>"; };
@@ -66,12 +71,21 @@
6671
isa = PBXFrameworksBuildPhase;
6772
buildActionMask = 2147483647;
6873
files = (
74+
488FE2A2200BCED100E05AB0 /* MediaPlayer.framework in Frameworks */,
6975
);
7076
runOnlyForDeploymentPostprocessing = 0;
7177
};
7278
/* End PBXFrameworksBuildPhase section */
7379

7480
/* Begin PBXGroup section */
81+
488FE2A0200BCEC900E05AB0 /* Frameworks */ = {
82+
isa = PBXGroup;
83+
children = (
84+
488FE2A1200BCEC900E05AB0 /* MediaPlayer.framework */,
85+
);
86+
name = Frameworks;
87+
sourceTree = "<group>";
88+
};
7589
669581FA1FE44191008596CD /* Permissions */ = {
7690
isa = PBXGroup;
7791
children = (
@@ -81,6 +95,8 @@
8195
669582001FE441A7008596CD /* RNPBackgroundRefresh.m */,
8296
669582091FE441A8008596CD /* RNPBluetooth.h */,
8397
669581FF1FE441A7008596CD /* RNPBluetooth.m */,
98+
488FE29D200BC8D200E05AB0 /* RNPMediaLibrary.h */,
99+
488FE29B200BC8A100E05AB0 /* RNPMediaLibrary.m */,
84100
669581FB1FE441A7008596CD /* RNPContacts.h */,
85101
669582081FE441A8008596CD /* RNPContacts.m */,
86102
669582061FE441A7008596CD /* RNPEvent.h */,
@@ -108,6 +124,7 @@
108124
669581F31FE4416B008596CD /* ReactNativePermissions.h */,
109125
669581F51FE4416B008596CD /* ReactNativePermissions.m */,
110126
9D23B3501C767B80008B4819 /* Products */,
127+
488FE2A0200BCEC900E05AB0 /* Frameworks */,
111128
);
112129
sourceTree = "<group>";
113130
};
@@ -176,6 +193,7 @@
176193
buildActionMask = 2147483647;
177194
files = (
178195
669582111FE441A8008596CD /* RNPNotification.m in Sources */,
196+
488FE29C200BC8A100E05AB0 /* RNPMediaLibrary.m in Sources */,
179197
669582151FE441A8008596CD /* RNPEvent.m in Sources */,
180198
669582101FE441A8008596CD /* RNPBackgroundRefresh.m in Sources */,
181199
669581F71FE4416B008596CD /* RCTConvert+RNPStatus.m in Sources */,

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-
'motion',
23+
'mediaLibrary',
24+
'motion'
2425
]
2526

2627
const DEFAULTS = {

0 commit comments

Comments
 (0)