Browse Source

mediaLibrary ios added

Rory Pickering 7 years ago
parent
commit
78f993bc6a

+ 2
- 0
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
 | Storage            | `storage`           | ❌️ | ✔       |
164
 | Storage            | `storage`           | ❌️ | ✔       |
164
 | Phone Call         | `callPhone`         | ❌️ | ✔       |
165
 | Phone Call         | `callPhone`         | ❌️ | ✔       |
165
 | Read SMS           | `readSms`           | ❌️ | ✔       |
166
 | Read SMS           | `readSms`           | ❌️ | ✔       |
186
 * Permission type `notification` accepts a second parameter for `request()`. The
187
 * Permission type `notification` accepts a second parameter for `request()`. The
187
   second parameter is an array with the desired alert types. Any combination of
188
   second parameter is an array with the desired alert types. Any combination of
188
   `alert`, `badge` and `sound` (default requests all three).
189
   `alert`, `badge` and `sound` (default requests all three).
190
+* If you are not requesting mediaLibrary then you can remove MediaPlayer.framework from the xcode project
189
 
191
 
190
 ```js
192
 ```js
191
 // example
193
 // example

+ 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

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

32
     RNPTypeBluetooth,
32
     RNPTypeBluetooth,
33
     RNPTypeNotification,
33
     RNPTypeNotification,
34
     RNPTypeBackgroundRefresh,
34
     RNPTypeBackgroundRefresh,
35
-    RNPTypeSpeechRecognition
35
+    RNPTypeSpeechRecognition,
36
+    RNPTypeMediaLibrary
36
 };
37
 };
37
 
38
 
38
 @interface RCTConvert (RNPStatus)
39
 @interface RCTConvert (RNPStatus)

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

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

+ 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
 
47
 
47
 @interface ReactNativePermissions()
48
 @interface ReactNativePermissions()
48
 @property (strong, nonatomic) RNPLocation *locationMgr;
49
 @property (strong, nonatomic) RNPLocation *locationMgr;
145
         case RNPTypeSpeechRecognition:
146
         case RNPTypeSpeechRecognition:
146
             status = [RNPSpeechRecognition getStatus];
147
             status = [RNPSpeechRecognition getStatus];
147
             break;
148
             break;
149
+        case RNPTypeMediaLibrary:
150
+            status = [RNPMediaLibrary getStatus];
151
+            break;
148
         default:
152
         default:
149
             break;
153
             break;
150
     }
154
     }
177
             return [self requestNotification:json resolve:resolve];
181
             return [self requestNotification:json resolve:resolve];
178
         case RNPTypeSpeechRecognition:
182
         case RNPTypeSpeechRecognition:
179
             return [RNPSpeechRecognition request:resolve];
183
             return [RNPSpeechRecognition request:resolve];
184
+        case RNPTypeMediaLibrary:
185
+            return [RNPMediaLibrary request:resolve];
180
         default:
186
         default:
181
             break;
187
             break;
182
     }
188
     }

+ 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 */; };
33
 /* End PBXCopyFilesBuildPhase section */
35
 /* End PBXCopyFilesBuildPhase section */
34
 
36
 
35
 /* Begin PBXFileReference section */
37
 /* Begin PBXFileReference section */
38
+		488FE29B200BC8A100E05AB0 /* RNPMediaLibrary.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNPMediaLibrary.m; sourceTree = "<group>"; };
39
+		488FE29D200BC8D200E05AB0 /* RNPMediaLibrary.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNPMediaLibrary.h; sourceTree = "<group>"; };
40
+		488FE2A1200BCEC900E05AB0 /* MediaPlayer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MediaPlayer.framework; path = System/Library/Frameworks/MediaPlayer.framework; sourceTree = SDKROOT; };
36
 		669581F31FE4416B008596CD /* ReactNativePermissions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReactNativePermissions.h; sourceTree = "<group>"; };
41
 		669581F31FE4416B008596CD /* ReactNativePermissions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReactNativePermissions.h; sourceTree = "<group>"; };
37
 		669581F41FE4416B008596CD /* RCTConvert+RNPStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+RNPStatus.m"; sourceTree = "<group>"; };
42
 		669581F41FE4416B008596CD /* RCTConvert+RNPStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+RNPStatus.m"; sourceTree = "<group>"; };
38
 		669581F51FE4416B008596CD /* ReactNativePermissions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReactNativePermissions.m; sourceTree = "<group>"; };
43
 		669581F51FE4416B008596CD /* ReactNativePermissions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReactNativePermissions.m; sourceTree = "<group>"; };
63
 			isa = PBXFrameworksBuildPhase;
68
 			isa = PBXFrameworksBuildPhase;
64
 			buildActionMask = 2147483647;
69
 			buildActionMask = 2147483647;
65
 			files = (
70
 			files = (
71
+				488FE2A2200BCED100E05AB0 /* MediaPlayer.framework in Frameworks */,
66
 			);
72
 			);
67
 			runOnlyForDeploymentPostprocessing = 0;
73
 			runOnlyForDeploymentPostprocessing = 0;
68
 		};
74
 		};
69
 /* End PBXFrameworksBuildPhase section */
75
 /* End PBXFrameworksBuildPhase section */
70
 
76
 
71
 /* Begin PBXGroup section */
77
 /* Begin PBXGroup section */
78
+		488FE2A0200BCEC900E05AB0 /* Frameworks */ = {
79
+			isa = PBXGroup;
80
+			children = (
81
+				488FE2A1200BCEC900E05AB0 /* MediaPlayer.framework */,
82
+			);
83
+			name = Frameworks;
84
+			sourceTree = "<group>";
85
+		};
72
 		669581FA1FE44191008596CD /* Permissions */ = {
86
 		669581FA1FE44191008596CD /* Permissions */ = {
73
 			isa = PBXGroup;
87
 			isa = PBXGroup;
74
 			children = (
88
 			children = (
78
 				669582001FE441A7008596CD /* RNPBackgroundRefresh.m */,
92
 				669582001FE441A7008596CD /* RNPBackgroundRefresh.m */,
79
 				669582091FE441A8008596CD /* RNPBluetooth.h */,
93
 				669582091FE441A8008596CD /* RNPBluetooth.h */,
80
 				669581FF1FE441A7008596CD /* RNPBluetooth.m */,
94
 				669581FF1FE441A7008596CD /* RNPBluetooth.m */,
95
+				488FE29D200BC8D200E05AB0 /* RNPMediaLibrary.h */,
96
+				488FE29B200BC8A100E05AB0 /* RNPMediaLibrary.m */,
81
 				669581FB1FE441A7008596CD /* RNPContacts.h */,
97
 				669581FB1FE441A7008596CD /* RNPContacts.h */,
82
 				669582081FE441A8008596CD /* RNPContacts.m */,
98
 				669582081FE441A8008596CD /* RNPContacts.m */,
83
 				669582061FE441A7008596CD /* RNPEvent.h */,
99
 				669582061FE441A7008596CD /* RNPEvent.h */,
103
 				669581F31FE4416B008596CD /* ReactNativePermissions.h */,
119
 				669581F31FE4416B008596CD /* ReactNativePermissions.h */,
104
 				669581F51FE4416B008596CD /* ReactNativePermissions.m */,
120
 				669581F51FE4416B008596CD /* ReactNativePermissions.m */,
105
 				9D23B3501C767B80008B4819 /* Products */,
121
 				9D23B3501C767B80008B4819 /* Products */,
122
+				488FE2A0200BCEC900E05AB0 /* Frameworks */,
106
 			);
123
 			);
107
 			sourceTree = "<group>";
124
 			sourceTree = "<group>";
108
 		};
125
 		};
171
 			buildActionMask = 2147483647;
188
 			buildActionMask = 2147483647;
172
 			files = (
189
 			files = (
173
 				669582111FE441A8008596CD /* RNPNotification.m in Sources */,
190
 				669582111FE441A8008596CD /* RNPNotification.m in Sources */,
191
+				488FE29C200BC8A100E05AB0 /* RNPMediaLibrary.m in Sources */,
174
 				669582151FE441A8008596CD /* RNPEvent.m in Sources */,
192
 				669582151FE441A8008596CD /* RNPEvent.m in Sources */,
175
 				669582101FE441A8008596CD /* RNPBackgroundRefresh.m in Sources */,
193
 				669582101FE441A8008596CD /* RNPBackgroundRefresh.m in Sources */,
176
 				669581F71FE4416B008596CD /* RCTConvert+RNPStatus.m in Sources */,
194
 				669581F71FE4416B008596CD /* RCTConvert+RNPStatus.m in Sources */,

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

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