1

我的应用程序中有此代码:

[[self assetsLibrary] assetForURL:info.media.url resultBlock:^(ALAsset *asset) {
    ALAssetRepresentation *rep = [asset defaultRepresentation];
    CGImageRef img = [rep fullScreenImage];
    photoLayer.contents =  img;
} failureBlock:^(NSError *error) {

}];

代码到达填充 img 变量的行并停在那里,应用程序锁定且没有错误。NSLog 回显出一个大小,所以我知道资产在那里。我不知道如何解决这个问题,它以前工作过,但刚刚停止!有没有人看到这里有什么不合适的地方?

这是网址的样子:

assets-library://asset/asset.JPG?id=36E68169-7BB4-48D7-B8E1-244234C9F1DA&ext=JPG

冻结时的堆栈跟踪:

Thread 1, Queue : NSManagedObjectContext Queue
#0  0x37b1af38 in syscall_thread_switch ()
#1  0x331a5978 in OSSpinLockLock$VARIANT$wfe ()
#2  0x3318bcae in pthread_once ()
#3  0x348f66e2 in _internalCheckSupportsDCTDownScaling ()
#4  0x348f63fa in _initalizeService ()
#5  0x3318bcde in pthread_once ()
#6  0x348f63ba in jpegService ()
#7  0x3497009c in FigCreateCGImageFromJPEG ()
#8  0x356b5728 in PLCreateImageFromDataWithFormat ()
#9  0x35a3205e in __block_global_0 ()
#10 0x356a03f4 in -[PLAssetsSaver requestSynchronousImageFromAsset:withFormat:completionBlock:] ()
#11 0x35a32028 in __40-[ALAssetRepresentation fullScreenImage]_block_invoke_0 ()
#12 0x35a387ec in __53-[ALAssetRepresentationPrivate _performBlockAndWait:]_block_invoke_0 ()
#13 0x328e79a0 in developerSubmittedBlockToNSManagedObjectContextPerform ()
#14 0x3121c5da in _dispatch_client_callout ()
#15 0x3121f80e in _dispatch_barrier_sync_f_invoke ()
#16 0x328e7b22 in -[NSManagedObjectContext performBlockAndWait:] ()
#17 0x35a351b2 in -[ALAssetsLibrary _performBlockAndWait:] ()
#18 0x35a385ac in -[ALAssetRepresentationPrivate _performBlockAndWait:] ()
#19 0x35a31f24 in -[ALAssetRepresentation fullScreenImage] ()
#20 0x0008a3ca in __31-[MasterTimeLine getPhotoItem:]_block_invoke_0 at /Users/jasoncandelora/Desktop/Glance/iOS/projects/VideoBuilderTest1/VideoBuilderTest1/MasterTimeLine.m:789
#21 0x35a371b2 in __block_global_14 ()
#22 0x3121c792 in _dispatch_call_block_and_release ()
#23 0x3121c5da in _dispatch_client_callout ()
#24 0x3121fe44 in _dispatch_main_queue_callback_4CF ()
#25 0x357ff1b0 in __CFRunLoopRun ()
#26 0x3577223c in CFRunLoopRunSpecific ()
#27 0x357720c8 in CFRunLoopRunInMode ()
#28 0x3702133a in GSEventRunModal ()
#29 0x340ec290 in UIApplicationMain ()
#30 0x0006eda4 in main at /Users/jasoncandelora/Desktop/Glance/iOS/projects/VideoBuilderTest1/VideoBuilderTest1/main.m:16


Thread 3, Queue : com.apple.libdispatch-manager
#0  0x37b1b5d0 in kevent64 ()
#1  0x31221d26 in _dispatch_mgr_invoke ()
#2  0x3121d378 in _dispatch_mgr_thread ()



Thread 5 WebThread, Queue : (null)
#0  0x37b1ae30 in mach_msg_trap ()
#1  0x37b1afd4 in mach_msg ()
#2  0x358002ba in __CFRunLoopServiceMachPort ()
#3  0x357ff030 in __CFRunLoopRun ()
#4  0x3577223c in CFRunLoopRunSpecific ()
#5  0x357720c8 in CFRunLoopRunInMode ()
#6  0x3376ea5c in RunWebThread(void*) ()
#7  0x331950e0 in _pthread_start ()
#8  0x33194fa8 in thread_start ()


Thread 8 com.apple.coremedia.player.async, Queue : (null)
#0  0x37b2b08c in __psynch_cvwait ()
#1  0x3318db00 in _pthread_cond_wait ()
#2  0x33197cfc in pthread_cond_wait ()
#3  0x336ef8b8 in FigSemaphoreWaitRelative ()
#4  0x39b30eae in fpa_AsyncMovieControlThread ()
#5  0x3370d97a in figThreadMain ()
#6  0x331950e0 in _pthread_start ()
#7  0x33194fa8 in thread_start ()





Thread 9 com.apple.coremedia.player.remote, Queue : (null)
#0  0x37b1ae30 in mach_msg_trap ()
#1  0x37b1afd4 in mach_msg ()
#2  0x39b370d8 in FigExpressNotificationThread ()
#3  0x3370d97a in figThreadMain ()
#4  0x331950e0 in _pthread_start ()
#5  0x33194fa8 in thread_start ()
4

3 回答 3

0

您不应该使用这种诡计来尝试将异步资产检索操作强制转换为同步操作。最可能的原因是死锁,检查各种线程的堆栈跟踪,您可能会看到多个线程在一个信号量上等待。

我建议你删除信号量锁定的东西,让操作是异步的。

另一个建议:您是否确定用户实际上已允许访问照片(iOS6 上的新隐私设置)?

关于您发布的堆栈输出:

我看到了 FigSemaphoreWaitRelative 和 OSSpinLockLock$VARIANT$wfe。第一个是等待信号量被解锁。后者是另一种形式的锁定,而系统显然会检查您尝试访问的媒体是否可以在硬件中解码(_internalCheckSupportsDCTDownScaling)。

由于某种原因,此操作不仅卡住了,而且还阻塞了线程 1 的主线程。您是否可能打开了一个媒体播放器视图(com.apple.coremedia.player.async),它阻塞了视频硬件,而这防止上述 DCTDownScaling 检查死锁?

长话短说:听起来你应该为此提交一个雷达,对我来说很像一个 iOS 错误。

于 2012-12-18T20:41:46.107 回答
0

尝试将最后一行代码移至主队列:

[[self assetsLibrary] assetForURL:info.media.url resultBlock:^(ALAsset *asset) {
    ALAssetRepresentation *rep = [asset defaultRepresentation];
    CGImageRef img = [rep fullScreenImage];
    dispatch_async(dispatch_get_main_queue(), ^{
        photoLayer.contents =  img;
    };
} failureBlock:^(NSError *error) {

}];

如果这不起作用,这是多大的资产?

于 2012-12-18T20:56:13.913 回答
0

就我而言,我重新启动了设备,它现在可以工作了。感谢你的帮助

于 2012-12-20T18:49:36.553 回答