如何以编程方式或强制方式调用UIImagePickerController委托[无需用户交互]? [英] How to call UIImagePickerController Delegate programmatically or forcefully [without user interaction]?

查看:109
本文介绍了如何以编程方式或强制方式调用UIImagePickerController委托[无需用户交互]?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我使用UiimagepickerController进行Video.in我的程序之间接收任何属于我的应用程序的Web服务,
i必须停止视频捕获并保存视频。

In my app, i have Used UiimagepickerController for taking Video.in bettween my programm received any web service Which belongs to my app, i have to stop Video Capture and save video.

我已经使用StopVideoCapture来做上面的事情,但是它没有调用委托 -

i have Used StopVideoCapture to do above thing ,but it doesn't call delegate - `


(void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info

(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info


如何强制调用上面的委托??或者如何处理中断处理
UIImagePickerController` ..任何想法?

How to force call above delegate ??.or How to handle interruption Handling inUIImagePickerController`.. any idea?

推荐答案

委托方法的想法不是你称之为他们叫你。

The idea with delegate methods is not that you call those methods - "They call you".

所以我不会考虑自己调用委托方法。但是,如果你使用模态对话(我猜这种选择器很常见)来呈现 UIImagePickerViewController ,那么你可以在委托方法之外关闭它:

So I would not consider calling the delegate method yourself a good practise. However, if you present the UIImagePickerViewController with a modal dialogue (which I guess is common for such a picker) then you can close it like this outside of your delegate method:

[[yourPicker parentViewController] dismissModalViewControllerAnimated:YES];

来源

更新:您可以使用 ALAssetsLibrary ,用于访问iPhone媒体库中存储的数据。我最近不得不做一个类似的项目,我必须列出iPhone上的所有图像。 Github项目 ELCImagePickerController.git 非常有用,因为它显示了如何访问库中的项目。所以你会做这样的事情:

Update: You can use the ALAssetsLibrary for accessing the stored data in your iPhone media library. I recently had to do a similar project where I had to list all images on the iPhone. The Github project ELCImagePickerController.git was very useful since it shows how the items in your library can be accessed. So you'll do something like this:

#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]];
     }];
}

此外,我使用两个映射器方法将AL类转换为我自己的模型class。

Additionally I use two mapper methods to convert the AL-classes into my own model classes.

- (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;
}

参见 AssetsLibrary文档

这篇关于如何以编程方式或强制方式调用UIImagePickerController委托[无需用户交互]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆