Pārlūkot izejas kodu

mediaLibrary ios added

Rory Pickering 6 gadus atpakaļ
vecāks
revīzija
78f993bc6a

+ 2
- 0
README.md Parādīt failu

@@ -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
 | Storage            | `storage`           | ❌️ | ✔       |
164 165
 | Phone Call         | `callPhone`         | ❌️ | ✔       |
165 166
 | Read SMS           | `readSms`           | ❌️ | ✔       |
@@ -186,6 +187,7 @@ The current supported permissions are:
186 187
 * Permission type `notification` accepts a second parameter for `request()`. The
187 188
   second parameter is an array with the desired alert types. Any combination of
188 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 192
 ```js
191 193
 // example

+ 17
- 0
ios/Permissions/RNPMediaLibrary.h Parādīt failu

@@ -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 Parādīt failu

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

+ 2
- 1
ios/RCTConvert+RNPStatus.h Parādīt failu

@@ -32,7 +32,8 @@ typedef NS_ENUM(NSInteger, RNPType) {
32 32
     RNPTypeBluetooth,
33 33
     RNPTypeNotification,
34 34
     RNPTypeBackgroundRefresh,
35
-    RNPTypeSpeechRecognition
35
+    RNPTypeSpeechRecognition,
36
+    RNPTypeMediaLibrary
36 37
 };
37 38
 
38 39
 @interface RCTConvert (RNPStatus)

+ 2
- 1
ios/RCTConvert+RNPStatus.m Parādīt failu

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

+ 6
- 0
ios/ReactNativePermissions.m Parādīt failu

@@ -43,6 +43,7 @@
43 43
 #import "RNPContacts.h"
44 44
 #import "RNPBackgroundRefresh.h"
45 45
 #import "RNPSpeechRecognition.h"
46
+#import "RNPMediaLibrary.h"
46 47
 
47 48
 @interface ReactNativePermissions()
48 49
 @property (strong, nonatomic) RNPLocation *locationMgr;
@@ -145,6 +146,9 @@ RCT_REMAP_METHOD(getPermissionStatus, getPermissionStatus:(RNPType)type json:(id
145 146
         case RNPTypeSpeechRecognition:
146 147
             status = [RNPSpeechRecognition getStatus];
147 148
             break;
149
+        case RNPTypeMediaLibrary:
150
+            status = [RNPMediaLibrary getStatus];
151
+            break;
148 152
         default:
149 153
             break;
150 154
     }
@@ -177,6 +181,8 @@ RCT_REMAP_METHOD(requestPermission, permissionType:(RNPType)type json:(id)json r
177 181
             return [self requestNotification:json resolve:resolve];
178 182
         case RNPTypeSpeechRecognition:
179 183
             return [RNPSpeechRecognition request:resolve];
184
+        case RNPTypeMediaLibrary:
185
+            return [RNPMediaLibrary request:resolve];
180 186
         default:
181 187
             break;
182 188
     }

+ 18
- 0
ios/ReactNativePermissions.xcodeproj/project.pbxproj Parādīt failu

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

+ 1
- 0
lib/permissions.ios.js Parādīt failu

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