Browse Source

Merge pull request #211 from rory-pickering/master

Ability to query mediaLibrary on ios
Mathieu Acthernoene 6 years ago
parent
commit
6e53aaddb9
No account linked to committer's email address

+ 4
- 1
README.md View File

@@ -160,6 +160,7 @@ The current supported permissions are:
160 160
 | Push Notifications | `notification`      | ✔️  | ❌      |
161 161
 | Background Refresh | `backgroundRefresh` | ✔️  | ❌      |
162 162
 | Speech Recognition | `speechRecognition` | ✔️  | ❌      |
163
+| mediaLibrary       | `mediaLibrary`      | ✔️  | ❌      |
163 164
 | Motion Activity    | `motion`            | ✔️  | ❌      |
164 165
 | Storage            | `storage`           | ❌️ | ✔       |
165 166
 | Phone Call         | `callPhone`         | ❌️ | ✔       |
@@ -187,6 +188,7 @@ The current supported permissions are:
187 188
 * Permission type `notification` accepts a second parameter for `request()`. The
188 189
   second parameter is an array with the desired alert types. Any combination of
189 190
   `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
190 192
 
191 193
 ```js
192 194
 // example
@@ -239,9 +241,10 @@ So before submitting your app to the App Store, make sure that in your
239 241
 <string>Some description</string>
240 242
 <key>NSSpeechRecognitionUsageDescription</key>
241 243
 <string>Some description</string>
244
+<key>NSAppleMusicUsageDescription</key>
245
+<string>Some description</string>
242 246
 <key>NSMotionUsageDescription</key>
243 247
 <string>Some description</string>
244
-```
245 248
 
246 249
 This is required because during the phase of processing in the App Store
247 250
 submission, the system detects that you app contains code to request the

+ 17
- 0
ios/Permissions/RNPMediaLibrary.h View File

@@ -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

+ 41
- 0
ios/Permissions/RNPMediaLibrary.m View File

@@ -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

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

@@ -33,6 +33,7 @@ typedef NS_ENUM(NSInteger, RNPType) {
33 33
     RNPTypeNotification,
34 34
     RNPTypeBackgroundRefresh,
35 35
     RNPTypeSpeechRecognition,
36
+    RNPTypeMediaLibrary
36 37
     RNPTypeMotion
37 38
 };
38 39
 

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

@@ -21,6 +21,7 @@ RCT_ENUM_CONVERTER(RNPType, (@{ @"location" : @(RNPTypeLocation),
21 21
                                 @"notification" : @(RNPTypeNotification),
22 22
                                 @"backgroundRefresh": @(RNPTypeBackgroundRefresh),
23 23
                                 @"speechRecognition": @(RNPTypeSpeechRecognition),
24
+                                @"mediaLibrary": @(RNPTypeMediaLibrary)
24 25
                                 @"motion": @(RNPTypeMotion)
25 26
                                 }),
26 27
                                 RNPTypeUnknown, integerValue)

+ 6
- 0
ios/ReactNativePermissions.m View File

@@ -43,8 +43,10 @@
43 43
 #import "RNPContacts.h"
44 44
 #import "RNPBackgroundRefresh.h"
45 45
 #import "RNPSpeechRecognition.h"
46
+#import "RNPMediaLibrary.h"
46 47
 #import "RNPMotion.h"
47 48
 
49
+
48 50
 @interface ReactNativePermissions()
49 51
 @property (strong, nonatomic) RNPLocation *locationMgr;
50 52
 @property (strong, nonatomic) RNPNotification *notificationMgr;
@@ -146,6 +148,8 @@ RCT_REMAP_METHOD(getPermissionStatus, getPermissionStatus:(RNPType)type json:(id
146 148
         case RNPTypeSpeechRecognition:
147 149
             status = [RNPSpeechRecognition getStatus];
148 150
             break;
151
+        case RNPTypeMediaLibrary:
152
+            status = [RNPMediaLibrary getStatus];
149 153
         case RNPTypeMotion:
150 154
             status = [RNPMotion getStatus];
151 155
             break;
@@ -181,6 +185,8 @@ RCT_REMAP_METHOD(requestPermission, permissionType:(RNPType)type json:(id)json r
181 185
             return [self requestNotification:json resolve:resolve];
182 186
         case RNPTypeSpeechRecognition:
183 187
             return [RNPSpeechRecognition request:resolve];
188
+        case RNPTypeMediaLibrary:
189
+            return [RNPMediaLibrary request:resolve];
184 190
         case RNPTypeMotion:
185 191
             return [RNPMotion request:resolve];
186 192
         default:

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

@@ -7,6 +7,8 @@
7 7
 	objects = {
8 8
 
9 9
 /* 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 */; };
10 12
 		669581F71FE4416B008596CD /* RCTConvert+RNPStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 669581F41FE4416B008596CD /* RCTConvert+RNPStatus.m */; };
11 13
 		669581F81FE4416B008596CD /* ReactNativePermissions.m in Sources */ = {isa = PBXBuildFile; fileRef = 669581F51FE4416B008596CD /* ReactNativePermissions.m */; };
12 14
 		6695820D1FE441A8008596CD /* RNPSpeechRecognition.m in Sources */ = {isa = PBXBuildFile; fileRef = 669581FD1FE441A7008596CD /* RNPSpeechRecognition.m */; };
@@ -34,6 +36,9 @@
34 36
 /* End PBXCopyFilesBuildPhase section */
35 37
 
36 38
 /* 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; };
37 42
 		669581F31FE4416B008596CD /* ReactNativePermissions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReactNativePermissions.h; sourceTree = "<group>"; };
38 43
 		669581F41FE4416B008596CD /* RCTConvert+RNPStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+RNPStatus.m"; sourceTree = "<group>"; };
39 44
 		669581F51FE4416B008596CD /* ReactNativePermissions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReactNativePermissions.m; sourceTree = "<group>"; };
@@ -66,12 +71,21 @@
66 71
 			isa = PBXFrameworksBuildPhase;
67 72
 			buildActionMask = 2147483647;
68 73
 			files = (
74
+				488FE2A2200BCED100E05AB0 /* MediaPlayer.framework in Frameworks */,
69 75
 			);
70 76
 			runOnlyForDeploymentPostprocessing = 0;
71 77
 		};
72 78
 /* End PBXFrameworksBuildPhase section */
73 79
 
74 80
 /* Begin PBXGroup section */
81
+		488FE2A0200BCEC900E05AB0 /* Frameworks */ = {
82
+			isa = PBXGroup;
83
+			children = (
84
+				488FE2A1200BCEC900E05AB0 /* MediaPlayer.framework */,
85
+			);
86
+			name = Frameworks;
87
+			sourceTree = "<group>";
88
+		};
75 89
 		669581FA1FE44191008596CD /* Permissions */ = {
76 90
 			isa = PBXGroup;
77 91
 			children = (
@@ -81,6 +95,8 @@
81 95
 				669582001FE441A7008596CD /* RNPBackgroundRefresh.m */,
82 96
 				669582091FE441A8008596CD /* RNPBluetooth.h */,
83 97
 				669581FF1FE441A7008596CD /* RNPBluetooth.m */,
98
+				488FE29D200BC8D200E05AB0 /* RNPMediaLibrary.h */,
99
+				488FE29B200BC8A100E05AB0 /* RNPMediaLibrary.m */,
84 100
 				669581FB1FE441A7008596CD /* RNPContacts.h */,
85 101
 				669582081FE441A8008596CD /* RNPContacts.m */,
86 102
 				669582061FE441A7008596CD /* RNPEvent.h */,
@@ -108,6 +124,7 @@
108 124
 				669581F31FE4416B008596CD /* ReactNativePermissions.h */,
109 125
 				669581F51FE4416B008596CD /* ReactNativePermissions.m */,
110 126
 				9D23B3501C767B80008B4819 /* Products */,
127
+				488FE2A0200BCEC900E05AB0 /* Frameworks */,
111 128
 			);
112 129
 			sourceTree = "<group>";
113 130
 		};
@@ -176,6 +193,7 @@
176 193
 			buildActionMask = 2147483647;
177 194
 			files = (
178 195
 				669582111FE441A8008596CD /* RNPNotification.m in Sources */,
196
+				488FE29C200BC8A100E05AB0 /* RNPMediaLibrary.m in Sources */,
179 197
 				669582151FE441A8008596CD /* RNPEvent.m in Sources */,
180 198
 				669582101FE441A8008596CD /* RNPBackgroundRefresh.m in Sources */,
181 199
 				669581F71FE4416B008596CD /* RCTConvert+RNPStatus.m in Sources */,

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

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