Приложение iOS на основе MediaPicker не воспроизводит все песни

Я искал в этом руководстве информацию о том, как найти песни в музыкальной библиотеке пользователя на их iPhone. Все работает так, как положено, за исключением того, что песни, купленные, но не на телефоне пользователя, не воспроизводятся.

Кто-нибудь знает, как это исправить, или знает, как проверить, куплена ли песня и установлена ​​ли она, а затем предупредить пользователя?

Ниже приведен код, который я использую из учебника, который выбирает и воспроизводит песни:

/*
 * This method is called when the user presses button. It displays a media picker
 * screen to the user configured to show only audio files.
 */
- (IBAction)pickSong:(id)sender
{
    MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeAnyAudio];
    [picker setDelegate:self];
    [picker setAllowsPickingMultipleItems: NO];
    [self presentViewController:picker animated:YES completion:NULL];

}


#pragma mark - Media Picker Delegate

/*
 * This method is called when the user chooses something from the media picker screen. It dismisses the media picker screen
 * and plays the selected song.
 */
- (void)mediaPicker:(MPMediaPickerController *) mediaPicker didPickMediaItems:(MPMediaItemCollection *) collection {

    // remove the media picker screen
    [self dismissViewControllerAnimated:YES completion:NULL];

    // grab the first selection (media picker is capable of returning more than one selected item,
    // but this app only deals with one song at a time)
    MPMediaItem *item = [[collection items] objectAtIndex:0];

    // display title of song in a navigation bar
    //NSString *title = [item valueForProperty:MPMediaItemPropertyTitle];
    //[_navBar.topItem setTitle:title];

    // get a URL reference to the selected item
    NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL];

    // pass the URL to playURL:, defined earlier in this file
    [self playURL:url];
}

0 ответов

Другие вопросы по тегам