ios 5.0 上的 assetForURL 不适用于设备
- (void)thumbnail:(NSNumber *)index{
__block NSNumber *number = [NSNumber numberWithInt:[index intValue]];
ALAssetsLibrary *library = [ALAssetsLibrary sharedALAssetsLibrary];
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
CGImageRef iref = [myasset thumbnail];
if (iref) {
[delegate thumbnailDidLoad:[UIImage imageWithCGImage:iref] withIndex:number];
}
NSLog(@"RESSSSSSSSSSSSSSSSSSSSSSSSSSSSSULT");
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"Error, can't get image - %@",[myerror localizedDescription]);
};
NSString *mediaurl = @"assets-library://asset/asset.JPG?id=5AF4118C-947D-4097-910E-47E19553039C&ext=JPG";
NSURL *asseturl = [NSURL URLWithString:mediaurl];
[library assetForURL:asseturl resultBlock:resultblock failureBlock:failureblock];
NSLog(@"asseturl %@",asseturl);
}
这是我的代码,我的块有问题 - 它们在模拟器 5.0 下工作,但在设备下根本不起作用,它不会在断点处停止,并且 NSLogs 不起作用。使用模拟器一切正常。注意:CLAuthorizationStatus == kCLAuthorizationStatusAuthorized
- (void)thumbnail:(NSNumber *)index{
__block NSNumber *number = [NSNumber numberWithInt:[index intValue]];
ALAssetsLibrary *library = [ALAssetsLibrary sharedALAssetsLibrary];
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
CGImageRef iref = [myasset thumbnail];
if (iref) {
[delegate thumbnailDidLoad:[UIImage imageWithCGImage:iref] withIndex:number];
}
NSLog(@"RESSSSSSSSSSSSSSSSSSSSSSSSSSSSSULT");
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"Error, can't get image - %@",[myerror localizedDescription]);
};
NSString *mediaurl = @"assets-library://asset/asset.JPG?id=5AF4118C-947D-4097-910E-47E19553039C&ext=JPG";
NSURL *asseturl = [NSURL URLWithString:mediaurl];
[library assetForURL:asseturl resultBlock:resultblock failureBlock:failureblock];
NSLog(@"asseturl %@",asseturl);
}
Here is my code and i have issue with my blocks - they works under simulator 5.0 but they don't work under device at all, it doesn't stop on break points and NSLogs don't work. With simulator all work correctly. Notice: CLAuthorizationStatus == kCLAuthorizationStatusAuthorized
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保整个函数 -
(void)thumbnail:(NSNumber *)index...
是从主线程执行的,或者您确定用户已授权您的应用使用位置服务。如果您在后台调用它并且尚未获得授权,则永远不会提示用户批准,并且不会调用结果块和失败块。Make sure that this whole function -
(void)thumbnail:(NSNumber *)index...
is either executed from the main thread or you are sure that the user has authorized your app to use location services. If you call it in the background and you don't yet have authorization, then the user will never be prompted for approval and neither the result nor failure blocks will be called.从 iOS5 开始 assetForURL 是异步工作的。确保您
在主线程上调用。最简单的方法是在主队列上使用dispatch_async。
干杯,
亨德里克
as of iOS5 assetForURL works async. Make sure you call
on the main thread. This is easiest accomplished by using dispatch_async on the main queue.
Cheers,
Hendrik