gpt4 book ai didi

objective-c - 我如何将 UIDocumentInteractionController 与 MPMediaPickerController 一起使用

转载 作者:太空狗 更新时间:2023-10-30 03:51:50 25 4
gpt4 key购买 nike

我实现了 MPMediaPickerController

- (IBAction)pickSong:(id)sender {
MPMediaPickerController *picker =
[[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];

picker.delegate = self;
picker.allowsPickingMultipleItems = NO;
picker.prompt = NSLocalizedString (@"Select any song from the list", @"Prompt to user to choose some songs to play");
picker.showsCloudItems = YES;

[self presentModalViewController: picker animated: YES];
}
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
{
[self dismissModalViewControllerAnimated: YES];
if (mediaItemCollection.count > 0) {
MPMediaItem *mediaItem = [mediaItemCollection.items objectAtIndex:0];
NSLog(@"%@ - %@, %@", [mediaItem valueForProperty:MPMediaItemPropertyTitle], [mediaItem valueForProperty:MPMediaItemPropertyArtist], [mediaItem valueForProperty:MPMediaItemPropertyAssetURL]);


self.fileURL = [mediaItem valueForProperty:MPMediaItemPropertyAssetURL];
}
}

- (void) mediaPickerDidCancel: (MPMediaPickerController *) mediaPicker
{
[self dismissModalViewControllerAnimated: YES];
}

我还单独实现了 UIDocumentInteractionController,以便能够在任何能够处理歌曲的应用程序中打开歌曲

- (IBAction)shareButtonPressed:(id)sender {
NSURL *url = [[NSBundle mainBundle] URLForResource:@"Song.mp3" withExtension:nil];
self.docController= [UIDocumentInteractionController interactionControllerWithURL:url];
[self.docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
}

现在我要做的是合并两者,我想分享从用户那里挑选的歌曲,这就是我保存歌曲的 URL self.fileURL = [mediaItem valueForProperty: MPMediaItemPropertyAssetURL]; 我对共享方法做了一个简单的更改

- (IBAction)shareButtonPressed:(id)sender {
NSURL *url = self.fileURL;
self.docController= [UIDocumentInteractionController interactionControllerWithURL:url];
[self.docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
}

我认为这会起作用,但我得到的是一个错误提示

* Assertion failure in -[UIDocumentInteractionController setURL:], /SourceCache/UIKit/UIKit-2903.23/UIDocumentInteractionController.m:1010 2013-10-28 03:14:10.294 ShareTest[1567:60b] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIDocumentInteractionController: invalid scheme ipod-library. Only the file scheme is supported.'

问题显然出在 URL 上,我没有很好地实现它,或者我认为一个解决方案是获取 MPMediaItem 的 NSData 并将其保存为我的应用程序中的 .mp3 文件,但我没有我也不知道如何实现这一点

提前致谢

最佳答案

问题在于您作为参数传递的 URL 类型。

您需要使用此方法:[NSURL fileURLWithPath:path]UIDocumentInteractionController 创建路径。

您创建的 URL 方案是 ipod-library,但需要是 file

关于objective-c - 我如何将 UIDocumentInteractionController 与 MPMediaPickerController 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19625820/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com