首页 文章

如何以编程方式或强制方式调用UIImagePickerController委托[无需用户交互]?

提问于
浏览
2

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

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

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

How to force call above delegate ??.or How to handle interruption Handling in UIImagePickerController` ..任何想法?

1 回答

  • 2

    委托方法的想法并不是你称这些方法 - “他们叫你” .

    所以我不认为自己调用委托方法是一个好习惯 . 但是,如果你给 UIImagePickerViewController 提供一个模态对话(我猜这种选择器很常见),那么你可以在你的委托方法之外关闭它:

    [[yourPicker parentViewController] dismissModalViewControllerAnimated:YES];
    

    Source

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

    #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类转换为我自己的模型类 .

    - (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 Documentation

相关问题