瀏覽代碼

Merge pull request #211 from rory-pickering/master

Ability to query mediaLibrary on ios
Mathieu Acthernoene 8 年之前
父節點
當前提交
6e53aaddb9

+ 4 - 1
README.md

@@ -160,6 +160,7 @@ The current supported permissions are:
 | Push Notifications | `notification`      | ✔️  | ❌      |
 | Push Notifications | `notification`      | ✔️  | ❌      |
 | Background Refresh | `backgroundRefresh` | ✔️  | ❌      |
 | Background Refresh | `backgroundRefresh` | ✔️  | ❌      |
 | Speech Recognition | `speechRecognition` | ✔️  | ❌      |
 | Speech Recognition | `speechRecognition` | ✔️  | ❌      |
+| mediaLibrary       | `mediaLibrary`      | ✔️  | ❌      |
 | Motion Activity    | `motion`            | ✔️  | ❌      |
 | Motion Activity    | `motion`            | ✔️  | ❌      |
 | Storage            | `storage`           | ❌️ | ✔       |
 | Storage            | `storage`           | ❌️ | ✔       |
 | Phone Call         | `callPhone`         | ❌️ | ✔       |
 | Phone Call         | `callPhone`         | ❌️ | ✔       |
@@ -187,6 +188,7 @@ The current supported permissions are:
 * Permission type `notification` accepts a second parameter for `request()`. The
 * Permission type `notification` accepts a second parameter for `request()`. The
   second parameter is an array with the desired alert types. Any combination of
   second parameter is an array with the desired alert types. Any combination of
   `alert`, `badge` and `sound` (default requests all three).
   `alert`, `badge` and `sound` (default requests all three).
+* If you are not requesting mediaLibrary then you can remove MediaPlayer.framework from the xcode project
 
 
 ```js
 ```js
 // example
 // example
@@ -239,9 +241,10 @@ So before submitting your app to the App Store, make sure that in your
 <string>Some description</string>
 <string>Some description</string>
 <key>NSSpeechRecognitionUsageDescription</key>
 <key>NSSpeechRecognitionUsageDescription</key>
 <string>Some description</string>
 <string>Some description</string>
+<key>NSAppleMusicUsageDescription</key>
+<string>Some description</string>
 <key>NSMotionUsageDescription</key>
 <key>NSMotionUsageDescription</key>
 <string>Some description</string>
 <string>Some description</string>
-```
 
 
 This is required because during the phase of processing in the App Store
 This is required because during the phase of processing in the App Store
 submission, the system detects that you app contains code to request the
 submission, the system detects that you app contains code to request the

+ 17 - 0
ios/Permissions/RNPMediaLibrary.h

@@ -0,0 +1,17 @@
+//
+//  RNPMediaLibrary.h
+//  ReactNativePermissions
+//
+//  Created by Yonah Forst on 11/07/16.
+//  Copyright © 2016 Yonah Forst. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import "RCTConvert+RNPStatus.h"
+
+@interface RNPMediaLibrary : NSObject
+
++ (NSString *)getStatus;
++ (void)request:(void (^)(NSString *))completionHandler;
+
+@end

+ 41 - 0
ios/Permissions/RNPMediaLibrary.m

@@ -0,0 +1,41 @@
+//
+//  RNPPhoto.m
+//  ReactNativePermissions
+//
+//  Created by Yonah Forst on 11/07/16.
+//  Copyright © 2016 Yonah Forst. All rights reserved.
+//
+
+#import "RNPMediaLibrary.h"
+#import <MediaPlayer/MediaPlayer.h>
+
+@implementation RNPMediaLibrary
+
++ (NSString *)getStatus
+{
+    int status = [MPMediaLibrary authorizationStatus];
+    switch (status) {
+        case MPMediaLibraryAuthorizationStatusAuthorized:
+            return RNPStatusAuthorized;
+        case MPMediaLibraryAuthorizationStatusDenied:
+            return RNPStatusDenied;
+        case MPMediaLibraryAuthorizationStatusRestricted:
+            return RNPStatusRestricted;
+        default:
+            return RNPStatusUndetermined;
+    }
+}
+
++ (void)request:(void (^)(NSString *))completionHandler
+{
+    void (^handler)(void) =  ^(void) {
+        dispatch_async(dispatch_get_main_queue(), ^{
+            completionHandler([self.class getStatus]);
+        });
+    };
+    
+    [MPMediaLibrary requestAuthorization:^(MPMediaLibraryAuthorizationStatus status){
+        handler();
+    }];
+}
+@end

+ 1 - 0
ios/RCTConvert+RNPStatus.h

@@ -33,6 +33,7 @@ typedef NS_ENUM(NSInteger, RNPType) {
     RNPTypeNotification,
     RNPTypeNotification,
     RNPTypeBackgroundRefresh,
     RNPTypeBackgroundRefresh,
     RNPTypeSpeechRecognition,
     RNPTypeSpeechRecognition,
+    RNPTypeMediaLibrary
     RNPTypeMotion
     RNPTypeMotion
 };
 };
 
 

+ 1 - 0
ios/RCTConvert+RNPStatus.m

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

+ 6 - 0
ios/ReactNativePermissions.m

@@ -43,8 +43,10 @@
 #import "RNPContacts.h"
 #import "RNPContacts.h"
 #import "RNPBackgroundRefresh.h"
 #import "RNPBackgroundRefresh.h"
 #import "RNPSpeechRecognition.h"
 #import "RNPSpeechRecognition.h"
+#import "RNPMediaLibrary.h"
 #import "RNPMotion.h"
 #import "RNPMotion.h"
 
 
+
 @interface ReactNativePermissions()
 @interface ReactNativePermissions()
 @property (strong, nonatomic) RNPLocation *locationMgr;
 @property (strong, nonatomic) RNPLocation *locationMgr;
 @property (strong, nonatomic) RNPNotification *notificationMgr;
 @property (strong, nonatomic) RNPNotification *notificationMgr;
@@ -146,6 +148,8 @@ RCT_REMAP_METHOD(getPermissionStatus, getPermissionStatus:(RNPType)type json:(id
         case RNPTypeSpeechRecognition:
         case RNPTypeSpeechRecognition:
             status = [RNPSpeechRecognition getStatus];
             status = [RNPSpeechRecognition getStatus];
             break;
             break;
+        case RNPTypeMediaLibrary:
+            status = [RNPMediaLibrary getStatus];
         case RNPTypeMotion:
         case RNPTypeMotion:
             status = [RNPMotion getStatus];
             status = [RNPMotion getStatus];
             break;
             break;
@@ -181,6 +185,8 @@ RCT_REMAP_METHOD(requestPermission, permissionType:(RNPType)type json:(id)json r
             return [self requestNotification:json resolve:resolve];
             return [self requestNotification:json resolve:resolve];
         case RNPTypeSpeechRecognition:
         case RNPTypeSpeechRecognition:
             return [RNPSpeechRecognition request:resolve];
             return [RNPSpeechRecognition request:resolve];
+        case RNPTypeMediaLibrary:
+            return [RNPMediaLibrary request:resolve];
         case RNPTypeMotion:
         case RNPTypeMotion:
             return [RNPMotion request:resolve];
             return [RNPMotion request:resolve];
         default:
         default:

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

@@ -7,6 +7,8 @@
 	objects = {
 	objects = {
 
 
 /* Begin PBXBuildFile section */
 /* Begin PBXBuildFile section */
+		488FE29C200BC8A100E05AB0 /* RNPMediaLibrary.m in Sources */ = {isa = PBXBuildFile; fileRef = 488FE29B200BC8A100E05AB0 /* RNPMediaLibrary.m */; };
+		488FE2A2200BCED100E05AB0 /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 488FE2A1200BCEC900E05AB0 /* MediaPlayer.framework */; };
 		669581F71FE4416B008596CD /* RCTConvert+RNPStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 669581F41FE4416B008596CD /* RCTConvert+RNPStatus.m */; };
 		669581F71FE4416B008596CD /* RCTConvert+RNPStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 669581F41FE4416B008596CD /* RCTConvert+RNPStatus.m */; };
 		669581F81FE4416B008596CD /* ReactNativePermissions.m in Sources */ = {isa = PBXBuildFile; fileRef = 669581F51FE4416B008596CD /* ReactNativePermissions.m */; };
 		669581F81FE4416B008596CD /* ReactNativePermissions.m in Sources */ = {isa = PBXBuildFile; fileRef = 669581F51FE4416B008596CD /* ReactNativePermissions.m */; };
 		6695820D1FE441A8008596CD /* RNPSpeechRecognition.m in Sources */ = {isa = PBXBuildFile; fileRef = 669581FD1FE441A7008596CD /* RNPSpeechRecognition.m */; };
 		6695820D1FE441A8008596CD /* RNPSpeechRecognition.m in Sources */ = {isa = PBXBuildFile; fileRef = 669581FD1FE441A7008596CD /* RNPSpeechRecognition.m */; };
@@ -34,6 +36,9 @@
 /* End PBXCopyFilesBuildPhase section */
 /* End PBXCopyFilesBuildPhase section */
 
 
 /* Begin PBXFileReference section */
 /* Begin PBXFileReference section */
+		488FE29B200BC8A100E05AB0 /* RNPMediaLibrary.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNPMediaLibrary.m; sourceTree = "<group>"; };
+		488FE29D200BC8D200E05AB0 /* RNPMediaLibrary.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNPMediaLibrary.h; sourceTree = "<group>"; };
+		488FE2A1200BCEC900E05AB0 /* MediaPlayer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MediaPlayer.framework; path = System/Library/Frameworks/MediaPlayer.framework; sourceTree = SDKROOT; };
 		669581F31FE4416B008596CD /* ReactNativePermissions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReactNativePermissions.h; sourceTree = "<group>"; };
 		669581F31FE4416B008596CD /* ReactNativePermissions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReactNativePermissions.h; sourceTree = "<group>"; };
 		669581F41FE4416B008596CD /* RCTConvert+RNPStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+RNPStatus.m"; sourceTree = "<group>"; };
 		669581F41FE4416B008596CD /* RCTConvert+RNPStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+RNPStatus.m"; sourceTree = "<group>"; };
 		669581F51FE4416B008596CD /* ReactNativePermissions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReactNativePermissions.m; sourceTree = "<group>"; };
 		669581F51FE4416B008596CD /* ReactNativePermissions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReactNativePermissions.m; sourceTree = "<group>"; };
@@ -66,12 +71,21 @@
 			isa = PBXFrameworksBuildPhase;
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			buildActionMask = 2147483647;
 			files = (
 			files = (
+				488FE2A2200BCED100E05AB0 /* MediaPlayer.framework in Frameworks */,
 			);
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 			runOnlyForDeploymentPostprocessing = 0;
 		};
 		};
 /* End PBXFrameworksBuildPhase section */
 /* End PBXFrameworksBuildPhase section */
 
 
 /* Begin PBXGroup section */
 /* Begin PBXGroup section */
+		488FE2A0200BCEC900E05AB0 /* Frameworks */ = {
+			isa = PBXGroup;
+			children = (
+				488FE2A1200BCEC900E05AB0 /* MediaPlayer.framework */,
+			);
+			name = Frameworks;
+			sourceTree = "<group>";
+		};
 		669581FA1FE44191008596CD /* Permissions */ = {
 		669581FA1FE44191008596CD /* Permissions */ = {
 			isa = PBXGroup;
 			isa = PBXGroup;
 			children = (
 			children = (
@@ -81,6 +95,8 @@
 				669582001FE441A7008596CD /* RNPBackgroundRefresh.m */,
 				669582001FE441A7008596CD /* RNPBackgroundRefresh.m */,
 				669582091FE441A8008596CD /* RNPBluetooth.h */,
 				669582091FE441A8008596CD /* RNPBluetooth.h */,
 				669581FF1FE441A7008596CD /* RNPBluetooth.m */,
 				669581FF1FE441A7008596CD /* RNPBluetooth.m */,
+				488FE29D200BC8D200E05AB0 /* RNPMediaLibrary.h */,
+				488FE29B200BC8A100E05AB0 /* RNPMediaLibrary.m */,
 				669581FB1FE441A7008596CD /* RNPContacts.h */,
 				669581FB1FE441A7008596CD /* RNPContacts.h */,
 				669582081FE441A8008596CD /* RNPContacts.m */,
 				669582081FE441A8008596CD /* RNPContacts.m */,
 				669582061FE441A7008596CD /* RNPEvent.h */,
 				669582061FE441A7008596CD /* RNPEvent.h */,
@@ -108,6 +124,7 @@
 				669581F31FE4416B008596CD /* ReactNativePermissions.h */,
 				669581F31FE4416B008596CD /* ReactNativePermissions.h */,
 				669581F51FE4416B008596CD /* ReactNativePermissions.m */,
 				669581F51FE4416B008596CD /* ReactNativePermissions.m */,
 				9D23B3501C767B80008B4819 /* Products */,
 				9D23B3501C767B80008B4819 /* Products */,
+				488FE2A0200BCEC900E05AB0 /* Frameworks */,
 			);
 			);
 			sourceTree = "<group>";
 			sourceTree = "<group>";
 		};
 		};
@@ -176,6 +193,7 @@
 			buildActionMask = 2147483647;
 			buildActionMask = 2147483647;
 			files = (
 			files = (
 				669582111FE441A8008596CD /* RNPNotification.m in Sources */,
 				669582111FE441A8008596CD /* RNPNotification.m in Sources */,
+				488FE29C200BC8A100E05AB0 /* RNPMediaLibrary.m in Sources */,
 				669582151FE441A8008596CD /* RNPEvent.m in Sources */,
 				669582151FE441A8008596CD /* RNPEvent.m in Sources */,
 				669582101FE441A8008596CD /* RNPBackgroundRefresh.m in Sources */,
 				669582101FE441A8008596CD /* RNPBackgroundRefresh.m in Sources */,
 				669581F71FE4416B008596CD /* RCTConvert+RNPStatus.m in Sources */,
 				669581F71FE4416B008596CD /* RCTConvert+RNPStatus.m in Sources */,

+ 2 - 1
lib/permissions.ios.js

@@ -20,7 +20,8 @@ const permissionTypes = [
   'notification',
   'notification',
   'backgroundRefresh',
   'backgroundRefresh',
   'speechRecognition',
   'speechRecognition',
-  'motion',
+  'mediaLibrary',
+  'motion'
 ]
 ]
 
 
 const DEFAULTS = {
 const DEFAULTS = {