Reputation: 9
I am working with the MPMediaPickerController controller.
Right now I am able to select an item from the gallery using the following code:
MPMediaPickerController *controller = [[MPMediaPickerController alloc]initWithMediaTypes:MPMediaTypeAnyAudio];
controller.delegate = mediaDelegate._pickerDelegate;
[self presentViewController:controller animated:YES completion:nil];
NSLog(@"url :%@",singleton.url);
The intention is that my method should return the URL of the selected item. Instead I am getting null
for the URL because the line below the present view controller gets called as soon as view controller presented (it is not waiting for selection of item).
Is there any way to stop after presentViewController
, for selection of item and then return the selected item URL from the method ?
Upvotes: 0
Views: 96
Reputation:
You have to write this
[self presentViewController:controller animated:YES completion:nil];
NSLog(@"url :%@",singleton.url);
in
- (void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection
method..
Upvotes: 0
Reputation: 20410
You need to implement the MPMediaPickerControllerDelegate
delegate:
- (void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection
When the user selects an item, that method will be called
Upvotes: 2