- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试使用 AssetForURL 方法,但它返回 nil。
这是我正在使用的代码:
-(void)addAssetURL:(NSURL*)assetURL toAlbum:(NSString*)albumName withCompletionBlock:(SaveImageCompletion)completionBlock
{
__block BOOL albumWasFound = NO;
//search all photo albums in the library
[self enumerateGroupsWithTypes:ALAssetsGroupAlbum
usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
//compare the names of the albums
if ([albumName compare: [group valueForProperty:ALAssetsGroupPropertyName]]==NSOrderedSame) {
//target album is found
albumWasFound = YES;
//get a hold of the photo's asset instance
[self assetForURL: assetURL
resultBlock:^(ALAsset *asset) {
//add photo to the target album
[group addAsset: asset];
//run the completion block
completionBlock(nil);
} failureBlock: completionBlock];
//album was found, bail out of the method
return;
}
if (group==nil && albumWasFound==NO) {
//photo albums are over, target album does not exist, thus create it
__weak ALAssetsLibrary* weakSelf = self;
//create new assets album
[self addAssetsGroupAlbumWithName:albumName
resultBlock:^(ALAssetsGroup *group) {
//get the photo's instance
[weakSelf assetForURL: assetURL
resultBlock:^(ALAsset *asset) {
//add photo to the newly created album
[group addAsset: asset];
//call the completion block
completionBlock(nil);
} failureBlock: completionBlock];
} failureBlock: completionBlock];
//should be the last iteration anyway, but just in case
return;
}
} failureBlock: completionBlock];
}
我给它的网址是:
file://localhost/private/var/mobile/Applications/6630FBD3-1212-4ED0-BC3B-0C23AEEFB267/tmp/capture-T0x1d56e310.tmp.N3SZXy/capturedvideo.MOV
我从相机委托(delegate)方法中获取 URL:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSLog(@"%@",[info objectForKey:UIImagePickerControllerMediaURL]);
[library addAssetURL:[info objectForKey:UIImagePickerControllerMediaURL] toAlbum:@"Compedia videos" withCompletionBlock:^(NSError *error) {
if (error!=nil) {
NSLog(@"Big error: %@", [error description]);
}
}];
}
有什么想法吗?
最佳答案
您确定可以访问资源库吗?不要忘记检查访问状态
ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];
if (status == ALAuthorizationStatusNotDetermined) {
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[ALAssetsLibrary authorizationStatus];
__block BOOL accessChecked = NO; /// *stop is not respected immediately
[library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if (accessChecked) return ;
*stop = YES;
accessChecked = YES;
} failureBlock:^(NSError *error){
}];
}
else {
BOOL granted = status == ALAuthorizationStatusAuthorized;
}
- (void)enumerateGroupsWithTypes:(ALAssetsGroupType)types usingBlock:(ALAssetsLibraryGroupsEnumerationResultsBlock)enumerationBlock failureBlock:(ALAssetsLibraryAccessFailureBlock)failureBlock
Description Invokes a given block passing as a parameter each of theasset groups that match the given asset group type. The results arepassed one by one to the caller by executing the enumeration block.This method is asynchronous. When groups are enumerated, the user maybe asked to confirm the application's access to the data; the method,though, returns immediately. You should perform whatever work you wantwith the assets in enumerationBlock.
If the user denies access to theapplication, or if no application is allowed to access the data, thefailureBlock is called.
关于objective-c - AssetForURL 返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16276163/
我只想使用 Swift 从 ios 8 中的 ALAsset 获取图像资源。 我使用 SNImagePicker 进行多张图片选取。 对于 objective-c,我使用这个: for (in
我正在尝试使用 AssetForURL 方法,但它返回 nil。 这是我正在使用的代码: -(void)addAssetURL:(NSURL*)assetURL toAlbum:(NSString*)
我想等待此代码执行后再继续,但由于这些 block 是异步调用的,我不知道该怎么做??? NSURL *asseturl; NSMutableArray *tmpListAsset = [[NSMut
我正在尝试将此代码从 obj-c 转换为 swift 2.1: [[ALAssetsLibrary new] assetForURL:info[UIImagePickerControllerRefer
在 MonoTouch 中: 我正在将相机中的图像放入 PhotoAlbum 中: ALAssetsLibrary library = new ALAssetsLibrary(); library.W
我正在尝试获取照片库中的图像,为此我正在使用 assetForURL,但我一直收到错误消息“无法使用类型为‘( NSURL, resultBlock: (ALAsset!) -> Void, (NSE
我正在尝试从用户选择的图像中读取 EXIF 数据。我为此使用 ALAssetLibrary。到目前为止,我已经设法获得了 assetForURL:resultBlock:failureBlock: 方
我正在尝试创建一个方法,该方法将为给定的 Assets url 返回一个 ALAsset。 (我需要稍后上传 Assets ,并希望在结果块之外使用结果进行上传。) + (ALAsset*) asse
我正在使用 UIImagePickerController 选择图像,但我还需要图像的名称和其他元数据信息。我可以在 UIImagePickerController 提供的 referenceURL
此代码在 iOS 7 中运行良好,但在 iOS 8.1 中,位于“我的照片流”相册中的所有 Assets 在结果 block 中都为零。 (不调用 failureBlock。)普通相册和共享相册工作正
我是一名优秀的程序员,十分优秀!