我在我的应用中有这个代码:
[[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 ()
答案 0 :(得分:0)
您不应该使用这种技巧来尝试强制异步资产检索操作进入同步操作。最有可能的原因是死锁,检查各种线程的堆栈跟踪,你可能会看到多个线程正在等待信号量。
我建议您删除信号量锁定内容并让操作异步。
另一个建议:您是否确保用户实际允许访问照片(iOS6上的新隐私设置)?
关于您发布的堆栈输出:
我看到了一个FigSemaphoreWaitRelative和OSSpinLockLock $ VARIANT $ wfe。第一个是等待信号量被解锁。后者是另一种形式的锁定,而系统显然会检查您尝试访问的媒体是否可以在硬件中解码(_internalCheckSupportsDCTDownScaling)。
由于某种原因,此操作不仅会卡住,而且还会阻塞主线程,即线程1.您是否打开了一个媒体播放器视图(com.apple.coremedia.player.async)阻止视频硬件和这可以防止上面的DCTDownScaling检查死锁?
长话短说:听起来你应该为此提交雷达,对我来说看起来像是一个iOS错误。
答案 1 :(得分: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) {
}];
如果这不起作用,这有多大的资产?
答案 2 :(得分:0)
在我的情况下,我重启了设备,现在正在运行。 谢谢你的帮助