ios 5.0 上的 assetForURL 不适用于设备

发布于 2024-12-11 02:29:10 字数 1108 浏览 2 评论 0原文

- (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷…雨湿花 2024-12-18 02:29:10

确保整个函数 - (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.

南笙 2024-12-18 02:29:10

从 iOS5 开始 assetForURL 是异步工作的。确保您

    [delegate thumbnailDidLoad:[UIImage imageWithCGImage:iref] withIndex:number];

在主线程上调用。最简单的方法是在主队列上使用dispatch_async。

干杯,

亨德里克

as of iOS5 assetForURL works async. Make sure you call

    [delegate thumbnailDidLoad:[UIImage imageWithCGImage:iref] withIndex:number];

on the main thread. This is easiest accomplished by using dispatch_async on the main queue.

Cheers,

Hendrik

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文