Browse Source

Merge pull request #211 from rory-pickering/master

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

+ 4
- 1
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
+| mediaLibrary       | `mediaLibrary`      | ✔️  | ❌      |
163
 | Motion Activity    | `motion`            | ✔️  | ❌      |
164
 | Motion Activity    | `motion`            | ✔️  | ❌      |
164
 | Storage            | `storage`           | ❌️ | ✔       |
165
 | Storage            | `storage`           | ❌️ | ✔       |
165
 | Phone Call         | `callPhone`         | ❌️ | ✔       |
166
 | Phone Call         | `callPhone`         | ❌️ | ✔       |
187
 * Permission type `notification` accepts a second parameter for `request()`. The
188
 * Permission type `notification` accepts a second parameter for `request()`. The
188
   second parameter is an array with the desired alert types. Any combination of
189
   second parameter is an array with the desired alert types. Any combination of
189
   `alert`, `badge` and `sound` (default requests all three).
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
 ```js
193
 ```js
192
 // example
194
 // example
239
 <string>Some description</string>
241
 <string>Some description</string>
240
 <key>NSSpeechRecognitionUsageDescription</key>
242
 <key>NSSpeechRecognitionUsageDescription</key>
241
 <string>Some description</string>
243
 <string>Some description</string>
244
+<key>NSAppleMusicUsageDescription</key>
245
+<string>Some description</string>
242
 <key>NSMotionUsageDescription</key>
246
 <key>NSMotionUsageDescription</key>
243
 <string>Some description</string>
247
 <string>Some description</string>
244
-```
245
 
248
 
246
 This is required because during the phase of processing in the App Store
249
 This is required because during the phase of processing in the App Store
247
 submission, the system detects that you app contains code to request the
250
 submission, the system detects that you app contains code to request the

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

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

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
     RNPTypeNotification,
33
     RNPTypeNotification,
34
     RNPTypeBackgroundRefresh,
34
     RNPTypeBackgroundRefresh,
35
     RNPTypeSpeechRecognition,
35
     RNPTypeSpeechRecognition,
36
+    RNPTypeMediaLibrary
36
     RNPTypeMotion
37
     RNPTypeMotion
37
 };
38
 };
38
 
39
 

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

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

+ 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 "RNPMediaLibrary.h"
46
 #import "RNPMotion.h"
47
 #import "RNPMotion.h"
47
 
48
 
49
+
48
 @interface ReactNativePermissions()
50
 @interface ReactNativePermissions()
49
 @property (strong, nonatomic) RNPLocation *locationMgr;
51
 @property (strong, nonatomic) RNPLocation *locationMgr;
50
 @property (strong, nonatomic) RNPNotification *notificationMgr;
52
 @property (strong, nonatomic) RNPNotification *notificationMgr;
146
         case RNPTypeSpeechRecognition:
148
         case RNPTypeSpeechRecognition:
147
             status = [RNPSpeechRecognition getStatus];
149
             status = [RNPSpeechRecognition getStatus];
148
             break;
150
             break;
151
+        case RNPTypeMediaLibrary:
152
+            status = [RNPMediaLibrary getStatus];
149
         case RNPTypeMotion:
153
         case RNPTypeMotion:
150
             status = [RNPMotion getStatus];
154
             status = [RNPMotion getStatus];
151
             break;
155
             break;
181
             return [self requestNotification:json resolve:resolve];
185
             return [self requestNotification:json resolve:resolve];
182
         case RNPTypeSpeechRecognition:
186
         case RNPTypeSpeechRecognition:
183
             return [RNPSpeechRecognition request:resolve];
187
             return [RNPSpeechRecognition request:resolve];
188
+        case RNPTypeMediaLibrary:
189
+            return [RNPMediaLibrary request:resolve];
184
         case RNPTypeMotion:
190
         case RNPTypeMotion:
185
             return [RNPMotion request:resolve];
191
             return [RNPMotion request:resolve];
186
         default:
192
         default:

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

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

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

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