Iphone 如何[无需用户交互]以编程方式或强制方式调用UIImagePickerController委托?
在我的应用程序中,我使用UiimagepickerController拍摄视频。在我的程序收到属于我的应用程序的任何web服务时, 我必须停止视频捕获并保存视频 我用StopVideoCapture做了以上的事情,但它不调用委托-` (无效)imagePickerController:(UIImagePickerController*)选择器 didFinishPickingMediaWithInfo:(NSDictionary*)信息Iphone 如何[无需用户交互]以编程方式或强制方式调用UIImagePickerController委托?,iphone,objective-c,ios4,uiimagepickercontroller,Iphone,Objective C,Ios4,Uiimagepickercontroller,在我的应用程序中,我使用UiimagepickerController拍摄视频。在我的程序收到属于我的应用程序的任何web服务时, 我必须停止视频捕获并保存视频 我用StopVideoCapture做了以上的事情,但它不调用委托-` (无效)imagePickerController:(UIImagePickerController*)选择器 didFinishPickingMediaWithInfo:(NSDictionary*)信息 如何在委托上方强制调用???。或者如何在UIImageP
如何在委托上方强制调用???。或者如何在
UIImagePickerController`…中处理中断处理。。有什么想法吗 委托方法的思想不是你调用那些方法——“他们调用你”
所以我不认为把委派方法称为一个好的练习。但是,如果在UIImagePickerViewController
中显示一个模式对话框(我想这对于这样的选择器来说是常见的),则可以在委托方法之外像这样关闭它:
[[yourPicker parentViewController] dismissModalViewControllerAnimated:YES];
更新:您可以使用访问iPhone媒体库中存储的数据。我最近不得不做一个类似的项目,列出iPhone上的所有图片。Github项目非常有用,因为它显示了如何访问库中的项。所以你可以这样做:
#import <AssetsLibrary/AssetsLibrary.h>
// ....
-(void)fetchPhotoAlbums{
if(!self.assetsGroups){
self.assetsGroups = [NSMutableDictionary dictionary];
}
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
NSMutableArray *returnArray = [[NSMutableArray alloc] init];
@autoreleasepool {
void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop){
if (group == nil){
// Completed
[self.delegate pictureService:self fetchedAlbums:returnArray];
return;
}
Album *currentAlbum = [self albumForAssetsGroup:group];
// Store the Group for later retrieving the pictures for the album
[self.assetsGroups setObject:group forKey:currentAlbum.identifier];
[returnArray addObject:currentAlbum];
[self.delegate pictureService:self fetchedAlbums:returnArray];
};
void (^assetGroupEnumberatorFailure)(NSError *) = ^(NSError *error) {
NSLog(@"A problem occured %@", [error description]);
};
[library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:assetGroupEnumerator
failureBlock:assetGroupEnumberatorFailure];
}
}
-(void)fetchPhotosForAlbum:(Album *)album{
ALAssetsGroup *currentGroup = [self.assetsGroups objectForKey:album.identifier];
NSMutableArray *photos = [NSMutableArray array];
[currentGroup enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop){
if(asset == nil){
[self.delegate pictureService:self fetchedPictures:photos forAlbum:album];
return;
}
[photos addObject:[self pictureForAsset:asset]];
}];
}
请参见然后我将如何获取录制的电影路径?@Astanienohpi我添加了一个如何读取媒体库内容的示例。所以你的电影将是这些资产之一。请注意,您的电影
ALAsset
对象将具有类型
“ALAssetTypeVideo”,并且可能位于alassetgroup
的alassetgroupType
属性为alassetgroupSavedPhotos
+1的alassetgroupType
中,以获取您的简短更新答案。我会检查这个代码。thanksI无法使用上述代码获取任何视频文件,我也有apple docu。请给出一些其他的解决方案。但我发现最后一个视频保存在应用程序的沙盒临时floder中,动态文件夹名为Capturexxxxx/capturedvideo.MOV-如何获取?请帮帮我
- (Album *)albumForAssetsGroup:(ALAssetsGroup *)assetsGroup{
Album *album = [[Album alloc] init];
album.title = [assetsGroup valueForProperty:ALAssetsGroupPropertyName];
album.identifier = [assetsGroup valueForProperty: ALAssetsGroupPropertyPersistentID];
album.assetsCount = assetsGroup.numberOfAssets;
album.thumbnail = [UIImage imageWithCGImage:assetsGroup.posterImage];
return album;
}
- (Picture *)pictureForAsset:(ALAsset *)asset{
Picture *picture = [[Picture alloc]init];
picture.identifier = [((NSArray *)[asset valueForProperty: ALAssetPropertyRepresentations]) objectAtIndex:0];
picture.thumbnail = [UIImage imageWithCGImage:asset.thumbnail];
return picture;
}