Last active
October 10, 2018 17:34
-
-
Save dmathewwws/2255ed8c0fea7ee4dd0b2ec13564d1eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation MediaPlayerIOSPodcastTitles | |
@synthesize bridge = _bridge; | |
// Export a native module | |
// https://facebook.github.io/react-native/docs/native-modules-ios.html | |
RCT_EXPORT_MODULE(); | |
// Export constants | |
// https://facebook.github.io/react-native/releases/next/docs/native-modules-ios.html#exporting-constants | |
- (NSDictionary *)constantsToExport | |
{ | |
return @{ | |
@"EXAMPLE": @"example" | |
}; | |
} | |
// Return the native view that represents your React component | |
- (UIView *)view | |
{ | |
return [[UIView alloc] init]; | |
} | |
- (NSArray<NSString *> *)supportedEvents{ | |
return @[@"podcast-titles"]; | |
} | |
// Export methods to a native module | |
// https://facebook.github.io/react-native/docs/native-modules-ios.html | |
RCT_REMAP_METHOD(getPodcastTitles, getPodcastTitlesWithResolver:(RCTPromiseResolveBlock)resolve | |
rejecter:(RCTPromiseRejectBlock)reject) | |
{ | |
[MPMediaLibrary requestAuthorization:^(MPMediaLibraryAuthorizationStatus status) { | |
if (status == MPMediaLibraryAuthorizationStatusAuthorized) { | |
MPMediaQuery *podcastsQuery = [MPMediaQuery podcastsQuery]; | |
NSMutableSet<NSString*> *podcastNameSet = [NSMutableSet set]; | |
for (MPMediaItem *podcast in podcastsQuery.items){ | |
NSString* unformattedPodcastTitle = podcast.podcastTitle; | |
if (unformattedPodcastTitle){ | |
NSString *podcastTitle = [unformattedPodcastTitle plusSignEncoding]; | |
[podcastNameSet addObject:podcastTitle]; | |
} | |
} | |
NSArray *podcastTitlesArray = [podcastNameSet allObjects]; | |
resolve(podcastTitlesArray); | |
}else{ | |
reject(@"300", @"Could not access your Podcast Library. Please adjust this in the Settings App", nil); | |
} | |
}]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Created by react-native-create-bridge | |
import { NativeModules } from 'react-native' | |
const { MediaPlayerIOSPodcastTitles } = NativeModules | |
export default { | |
getPodcastTitles () { | |
return MediaPlayerIOSPodcastTitles.getPodcastTitles() | |
}, | |
EXAMPLE_CONSTANT: MediaPlayerIOSPodcastTitles.EXAMPLE_CONSTANT | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "NSString+StringUtils.h" | |
@implementation NSString (StringUtils) | |
-(NSString*)plusSignEncoding{ | |
NSArray<NSString*>* words = [self componentsSeparatedByString:@" "]; | |
return [words componentsJoinedByString:@"+"]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment