首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >与空投共享视频

与空投共享视频
EN

Stack Overflow用户
提问于 2015-09-02 05:44:58
回答 1查看 475关注 0票数 1

我有一些困难,在分享视频与空投。所以,我像这样使用AssetLibrary

代码语言:javascript
复制
else if (conformsToVideo) {

        UIAlertView *alert = [[UIAlertView alloc]  initWithTitle:@"Asset Loaded" message:@"Video One Loaded"
        delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];

        self.mediaAsset = [AVAsset assetWithURL:[info objectForKey:UIImagePickerControllerMediaURL]];

        UIActivityViewController * controller = [[UIActivityViewController alloc] initWithActivityItems:@[self.mediaAsset] applicationActivities:nil];
        [self presentViewController:controller animated:YES completion:nil];
}

也许这不是做它的方式,我不知道,我也没有找到任何关于它的教程,所以如果你有一个,我很乐意接受它。

现在我的问题是,当我选择一个视频时,一切正常工作直到UIActivityViewController弹出,我没有任何错误,但我不能使用空投(nor any other service BTW),我唯一能做的就是按下Cancel button of UIAVController

我正在使用iOS 8.3

谢谢你的帮忙

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-03 05:11:13

好的,最后我找到了一个答案,也许不是最好的答案,但我把它放在那里,以防它帮助别人,因为我在与空投分享视频时没有发现太多:

代码语言:javascript
复制
NSURL * path = [info objectForKey:UIImagePickerControllerReferenceURL];
BOOL conformsToVideo = (UTTypeConformsTo((__bridge_retained CFStringRef) mediaType, kUTTypeAudiovisualContent));

if (conformsToVideo) {

            [self.library assetForURL:path
                          resultBlock:^(ALAsset *asset) {
                              ALAssetRepresentation* assetRepresentation = [asset defaultRepresentation];
                              NSString* outputDirectory = [NSString stringWithFormat:@"%@", NSTemporaryDirectory()];
                              NSString* pathToCopy = [outputDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@", assetRepresentation.filename]];

                              NSUInteger size = (NSUInteger)assetRepresentation.size;
                              NSMutableData* data = [NSMutableData dataWithLength:size];

                              NSUInteger bytesRead = [assetRepresentation getBytes:data.mutableBytes fromOffset:0 length:size error:nil];
                              NSURL * url = nil;
                              if ([data writeToFile:pathToCopy atomically:YES])
                              {
                                  NSLog(@"Ok");
                                  url = [NSURL fileURLWithPath:pathToCopy];
                                  UIActivityViewController * controller = [[UIActivityViewController alloc] initWithActivityItems:@[url] applicationActivities:nil];
                                  [self presentViewController:controller animated:YES completion:nil];
                              }
                          } failureBlock:^(NSError *error) {
                              NSLog(@"Failure to use the ALAsset");

                          }
             ];
        }

我使用这个问题找到了解决方案:Share a video from asset library with AirDrop fails --我只是将前面的步骤添加到给出的代码中,希望它能有用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32345420

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档