修复致命的iOS崩溃

时间:2015-06-28 20:32:14

标签: ios objective-c iphone xcode uiscrollview

`我正在AdHoc测试一个应用程序,它允许您登录到apache服务器,拍摄照片,并将它们作为jpeg thumb上传到UIScrollView。从那里你可以点击拇指全屏查看。该应用程序在iPad上完美运行,但当我点击拇指在iPhone 4上全屏查看时,应用程序崩溃/冻结,编译器突出显示以下代码行

    Thread 1: EXC_BAD_ACCESS(code=1, address=0xf6c04478)

    //code compiler highlights simultaneously when the app freezes on iPhone 4
    [api commandWithParams:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"stream", @"command", IdPhoto,@"IdPhoto", nil] onCompletion:^(NSDictionary *json) {

***EDIT***
After the debugger displays (lldb) and I type 'bt' this is what is displayed:

    * thread #1: tid = 0x5a399, 0x3931598e libobjc.A.dylib`lookUpImpOrForward + 46, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xf6c04478)
    frame #0: 0x3931598e libobjc.A.dylib`lookUpImpOrForward + 46
    frame #1: 0x39315956 libobjc.A.dylib`_class_lookupMethodAndLoadCache3 + 34
    frame #2: 0x3931a8b8 libobjc.A.dylib`_objc_msgSend_uncached + 24
    frame #3: 0x2ea9b5a8 CoreFoundation`+[__NSDictionaryM __new:::::] + 536
    frame #4: 0x2ea9e2f0 CoreFoundation`-[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 240
    frame #5: 0x2eaa2dcc CoreFoundation`+[NSDictionary dictionaryWithObjectsAndKeys:] + 372
  * frame #6: 0x0002c07c faunna`-[StreamPhotoScreen viewDidLoad](self=0x17f86c70, _cmd=0x319d0af3) + 200 at StreamPhotoScreen.m:8
    frame #7: 0x313814aa UIKit`-[UIViewController loadViewIfRequired] + 518
    frame #8: 0x31381268 UIKit`-[UIViewController view] + 24
    frame #9: 0x3150d36a UIKit`-[UINavigationController _startCustomTransition:] + 634
    frame #10: 0x3142ad62 UIKit`-[UINavigationController _startDeferredTransitionIfNeeded:] + 418
    frame #11: 0x3142ab6c UIKit`-[UINavigationController __viewWillLayoutSubviews] + 44
    frame #12: 0x3142ab04 UIKit`-[UILayoutContainerView layoutSubviews] + 184
    frame #13: 0x3137cd58 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 380
    frame #14: 0x30ffa62a QuartzCore`-[CALayer layoutSublayers] + 142
    frame #15: 0x30ff5e3a QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 350
    frame #16: 0x30ff5ccc QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
    frame #17: 0x30ff56de QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 230
    frame #18: 0x30ff54ee QuartzCore`CA::Transaction::commit() + 314
    frame #19: 0x30fef21c QuartzCore`CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 56
    frame #20: 0x2eb2b254 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
    frame #21: 0x2eb28bf8 CoreFoundation`__CFRunLoopDoObservers + 284
    frame #22: 0x2eb28f3a CoreFoundation`__CFRunLoopRun + 730
    frame #23: 0x2ea93ebe CoreFoundation`CFRunLoopRunSpecific + 522
    frame #24: 0x2ea93ca2 CoreFoundation`CFRunLoopRunInMode + 106
    frame #25: 0x33999662 GraphicsServices`GSEventRunModal + 138
    frame #26: 0x313e014c UIKit`UIApplicationMain + 1136
    frame #27: 0x0003f6dc faunna`main(argc=1, argv=0x27de1d14) + 108 at main.m:14
(lldb) 

这是完整的streamphotoscreen ......

#import "StreamPhotoScreen.h"
#import "API.h"
@implementation StreamPhotoScreen
@synthesize IdPhoto;
-(void)viewDidLoad {
API* api = [API sharedInstance];
//load the caption of the selected photo
[api commandWithParams:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"stream", @"command", IdPhoto,@"IdPhoto", nil] onCompletion:^(NSDictionary *json) {
    //show the text in the label
    NSArray* list = [json objectForKey:@"result"];
    NSDictionary* photo = [list objectAtIndex:0];
    lblTitle.text = [photo objectForKey:@"title"];
}];
//load the big size photo
NSURL* imageURL = [api urlForImageWithId:IdPhoto isThumb:NO];
[photoView setImageWithURL: imageURL];
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
@end

为什么应用程序崩溃了?可能是iPhone本身吗?

1 个答案:

答案 0 :(得分:0)

崩溃发生在StreamPhotoScreen的viewDidLoad方法中。发生了以下几件事之一:1。您在该方法中有代码导致崩溃。 2.视图存在连接问题。 3.其他。如果方法中有任何代码,请将方法代码添加到问题中。如果不仔细检查视图中的所有连接,委托和类名。

它可能正在使用iOS5及更高版本的API,但通常很容易在崩溃跟踪中找到。您需要设置断点并调试调试器。调试是一种技能集,与编写代码一样重要,至少在早期和许多情况下都是如此。

运行静态分析器:菜单:产品:分析器。单击twisties以查看执行路径并修复所有警告。在Xcode 7中做同样的事情,它应该具有更好的诊断功能。