Ios8 使用GenerateGimagesAsSynchronouslyFortimes生成缩略图将冻结屏幕,直到在iOS 8中生成图像

Ios8 使用GenerateGimagesAsSynchronouslyFortimes生成缩略图将冻结屏幕,直到在iOS 8中生成图像,ios8,Ios8,我正在尝试使用GenerateGimagesAsSynchronouslyFortimes从http url生成缩略图。这在ios 7.1中运行得非常好。但在我升级到iOS 8之后,它就不能以异步方式工作了。在生成图像之前,屏幕会冻结 以下是我尝试使用的代码: AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL URLWithString:videoContentIDFullPath] options:nil]; AVAsset

我正在尝试使用GenerateGimagesAsSynchronouslyFortimes从http url生成缩略图。这在ios 7.1中运行得非常好。但在我升级到iOS 8之后,它就不能以异步方式工作了。在生成图像之前,屏幕会冻结

以下是我尝试使用的代码:

AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL URLWithString:videoContentIDFullPath] options:nil];

AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generator.appliesPreferredTrackTransform=TRUE;

CMTime thumbTime = CMTimeMakeWithSeconds(30,30);

AVAssetImageGeneratorCompletionHandler handler = ^(CMTime requestedTime, CGImageRef im, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error){
    if (result != AVAssetImageGeneratorSucceeded) {
        NSLog(@"couldn't generate thumbnail, error:%@", error);
    }
    // TODO Do something with the image
    self.imageview.image = [[UIImage alloc] initWithCGImage:im];;

};

CGSize maxSize = CGSizeMake(128, 128);
generator.maximumSize = maxSize;
[generator generateCGImagesAsynchronouslyForTimes:[NSArray arrayWithObject:[NSValue valueWithCMTime:thumbTime]] completionHandler:handler];
你可以试试这个:

     __weak typeof(self) weakSelf = self; <--

    AVAssetImageGeneratorCompletionHandler handler = ^(CMTime requestedTime, CGImageRef im, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error){
        if (result != AVAssetImageGeneratorSucceeded) {
            NSLog(@"couldn't generate thumbnail, error:%@", error);
        }
        dispatch_async(dispatch_get_main_queue(), ^{ <--
            // TODO Do something with the image
            weakSelf.imageview.image = [[UIImage alloc] initWithCGImage:im]; <--
        });

    };

\uuuu弱类型(自我)弱自我=self;你找到解决办法了吗?面对同样的问题