在我的应用程序中,我需要从模拟器中获取视频,我需要上传到server.can任何一个帮助给我。请尽快提供任何解决方案。
谢谢&问候 T.swathi
答案 0 :(得分:1)
首先,创建一个UIImagePickerController
在您的课程中,您需要实现UIImagePickerControllerDelegate协议并将其连接到选择器上的delegate属性。一旦用户选择了某些内容,您应该能够获得从didFinishPickingMediaWithInfo中选择的媒体的位置。
//在iOS设备中检入不在模拟器中
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// this is the file system url of the media
NSURL* videoUrl = [info objectForKey:UIImagePickerControllerMediaURL];
// TODO: read in data at videoUrl and write upload it to your server
}
答案 1 :(得分:0)
使用此功能可能会有所帮助
-(void)selectVideoButtonClicked:(id)sender{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
[self presentViewController:imagePicker animated:YES completion:nil];
}
并删除“UIImagePickerControllerDelegate”&并导入框架并使用委托函数从库中选择视频
首先在项目中导入MobileCoreServices.framework,然后在文件CoreServices / CoreServices.h中导入
- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info {
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
// Handle a movie capture
if (CFStringCompare ((CFStringRef) mediaType, kUTTypeMovie, 0)
== kCFCompareEqualTo) {
NSString *moviePath = [[info objectForKey: UIImagePickerControllerMediaURL] path];
NSLog(@" Video Path %@",moviePath);
NSString *fileName = [[NSString alloc]init];
//If you wants get File Name Then you can use this
if ([moviePath rangeOfString:@"//"].location != NSNotFound) {
NSString *separatorString = @"//";
NSArray *disSplit = [moviePath componentsSeparatedByString:separatorString];
fileName = disSplit[1] ;
// [self videoUploadingDirect:moviePath];
}
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);
}
}
[self dismissViewControllerAnimated:YES completion:nil];
}
谢谢:)