繁体   English   中英

保存照片时崩溃

[英]Crash when save a photo

UIImage保存到相机胶卷时发生奇怪的崩溃。 我使用此代码:

UIImageWriteToSavedPhotosAlbum (_originalImage, self,  @selector(photoSaved:didFinishSavingWithError:contextInfo:), nil);

-(void)photoSaved:(UIImage*)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo {
if(!error){
    NSLog(@"Photo saved to library!");
} else{
    NSLog(@"Saving failed :(");
}

}

这是日志:

2012-11-10 20:43:29.868 MyApp[5012:1a303] Photo saved to library!

这是BT:

(lldb) bt
* thread #1: tid = 0x1f03, 0x024e509b libobjc.A.dylib`objc_msgSend + 15, stop reason = EXC_BAD_ACCESS (code=1, address=0x3094a576)
frame #0: 0x024e509b libobjc.A.dylib`objc_msgSend + 15
frame #1: 0x01b84a8b PhotoLibrary`-[PLUILibraryViewController updateNavigationItemButtons] + 216
frame #2: 0x01b6f054 PhotoLibrary`-[PLLibraryViewController(OverridePoints) updateInterfaceForHasContentChange] + 867
frame #3: 0x01c3c228 PhotoLibrary`-[PLAbstractLibraryViewController _updateHasContent] + 295
frame #4: 0x01c3c7d0 PhotoLibrary`-[PLAbstractLibraryViewController _updateAlbumsWithNotification:] + 681
frame #5: 0x01c3b870 PhotoLibrary`-[PLAbstractLibraryViewController albumListDidChange:] + 272
frame #6: 0x01b84c5b PhotoLibrary`-[PLUILibraryViewController albumListDidChange:] + 236
frame #7: 0x01525a29 Foundation`__57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_0 + 40
frame #8: 0x0267d855 CoreFoundation`___CFXNotificationPost_block_invoke_0 + 85
frame #9: 0x0267d778 CoreFoundation`_CFXNotificationPost + 1976
frame #10: 0x0146a234 Foundation`-[NSNotificationCenter postNotification:] + 121
frame #11: 0x02d217a4 PhotoLibraryServices`-[PLChangeNotificationCenter _postEnqueuedNotifications] + 425
frame #12: 0x02d1f771 PhotoLibraryServices`-[PLChangeNotificationCenter _sendNotificationsForSplitChanges] + 307
frame #13: 0x02d23614 PhotoLibraryServices`-[PLChangeNotificationCenter managedObjectContext:didProcessRemoteContextSave:usingObjectIDs:] + 56
frame #14: 0x02d017cc PhotoLibraryServices`-[PLSharedManagedObjectContext _mergeChangesFromDidSaveDictionary:usingObjectIDs:] + 229
frame #15: 0x03edfd2f CoreData`__+[NSManagedObjectContext(_NSCoreDataSPI) _mergeChangesFromRemoteContextSave:intoContexts:]_block_invoke_4 + 159
frame #16: 0x03e67d03 CoreData`developerSubmittedBlockToNSManagedObjectContextPerform + 99
frame #17: 0x01af18d9 libdispatch.dylib`_dispatch_barrier_sync_f_slow_invoke + 93
frame #18: 0x01af2509 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 353
frame #19: 0x025e9803 CoreFoundation`__CFRunLoopRun + 2003
frame #20: 0x025e8d84 CoreFoundation`CFRunLoopRunSpecific + 212
frame #21: 0x025e8c9b CoreFoundation`CFRunLoopRunInMode + 123
frame #22: 0x02a2d7d8 GraphicsServices`GSEventRunModal + 190
frame #23: 0x02a2d88a GraphicsServices`GSEventRun + 103
frame #24: 0x00b63626 UIKit`UIApplicationMain + 1163
frame #25: 0x000026ca MyApp`main + 170 at main.m:16

完全披露:我希望这是有道理的,因为我对 Objective-C 还很陌生,但我最近遇到了类似的问题。 当我从相机胶卷中选择图像后调用didFinishSavingWithError:contextInfo:方法时,我发现我的图像没有被保留。 对我withObject:是将withObject:参数添加到我的方法调用中,如下所示:

[self performSelector:@selector(image:didFinishSavingWithError:contextInfo:) withObject:_originalImage];

这样,当didFinishSavgngWithError:contextInfo:方法被调用时,图像会被保留,而之前没有。 同样,我是 Objective-C 的新手,但我希望这会有所帮助……或者至少为您指明正确的方向。 如果你能告诉我你的应用程序在什么时候崩溃(即当你调用 imagePicker 时,当你从相机胶卷中选择一个图像时,等等),这也很有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM