Ios 与airdrop共享视频
我在与airdrop共享视频时遇到一些问题。因此,我使用的Ios 与airdrop共享视频,ios,video,avasset,airdrop,Ios,Video,Avasset,Airdrop,我在与airdrop共享视频时遇到一些问题。因此,我使用的资产库如下所示: else if (conformsToVideo) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Asset Loaded" message:@"Video One Loaded" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
资产库如下所示:
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
弹出,我没有任何错误,但我不能使用airdrop(或任何其他服务,顺便说一句
),我唯一能做的就是按下UIAVController
的取消按钮
我正在使用iOS 8.3
谢谢你的帮助好的,最终我找到了一个答案,也许不是最好的,但我把它放在了那里,以防它对某人有所帮助,因为我在与airdrop共享视频方面没有找到太多东西:
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");
}
];
}
我通过这个问题找到了解决方案:
我只是将前面的步骤添加到这里给出的代码中,希望它能有用。好的,最终我找到了一个答案,可能不是最好的,但我把它放在那里,以防它对其他人有帮助,因为我在与airdrop共享视频方面没有发现太多:
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");
}
];
}
我通过这个问题找到了解决方案:
我只是将前面的步骤添加到这里给出的代码中,希望它能有用