iOS拍照后使用该图片(获取照片的ALasset传到相册)

问题:
拍照后,点击选择照片在-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 的代理方法中获取了相册的Alasset后,发现为空

解决办法:

-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
    if ([type isEqualToString:@"public.image"])
    {
        //先把图片转成NSData
        UIImage* image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
     ALAssetsLibrary *library  = [[ALAssetsLibrary alloc] init];
        [library writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
            if (error) {
                // TODO: error handling
            } else {
                [library  assetForURL:assetURL resultBlock:^(ALAsset *asset) {
                    [self.selectPhotos addObject:asset];
                    [_imageCollection reloadData];
                } failureBlock:^(NSError *error) {

                }];
            }
        }];
    }
}
展开阅读全文

没有更多推荐了,返回首页