How to do it...

  1. Let's start by opening the iOS Project in Xcode located in the ios directory of the new React Native app.
  2. Next, we'll create a new Objective-C Cocoa class called MediaManager.
  3. In the MediaManager header (.h) file, we need to import MPMediaPickerController and MPMusicPlayerController, along with the React Native bridge (RCTBridgeModule), as follows:
#import <Foundation/Foundation.h>#import <MediaPlayer/MediaPlayer.h>#import <React/RCTBridgeModule.h>#import <React/RCTEventDispatcher.h>@interface MediaManager : NSObject<RCTBridgeModule, MPMediaPickerControllerDelegate>@property (nonatomic, retain) MPMediaPickerController *mediaPicker;@property (nonatomic, retain) MPMusicPlayerController *musicPlayer;@end
  1. First, we are going ...

Get React Native Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.