Search code examples
iosuiviewcontrollerviewdidload

Getting Address Book permission crashes app iOS


I'm working on an iOS 7.1 app on Xcode 5.1.1 (can't be upgraded currently), with ARC and without a StoryBoard, and when I call an empty method in the viewDidLoad method, the app crashes at the end of my custom method. Currently, I'm thinking that it's either my older version of Xcode, or the fact that I'm not using a StoryBoard, but I've simplified the code as much as possible and still cannot find the error. if someone could point out what I'm doing wrong, that would be great, thanks!

The crash just says Thread 1: breakpoint 1.1, crashing when [self.window makeKeyAndVisible] calls [viewController viewDidLoad].

ViewController.h

@interface XYZContactsTableViewController : UITableViewController

@end

ViewController.m:

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {

    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self getAddressBook];
}

- (void)getAddressBook {

} // App crashes at line point exactly

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    XYZContactsTableViewController *viewController = [[XYZContactsTableViewController alloc] init];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}

Edits: Also, calling pure C functions in the viewDidLoad method works, so the problem has something to do with the viewController object.


Solution

  • The crash just says Thread 1: breakpoint 1.1

    Aha. You are not crashing at all. You are just pausing at a breakpoint. If you don't want to pause, or if breakpoints confuse you, take the breakpoint away or turn breakpoints off. Breakpoints are great, but you clearly don't understand them, so turn them off for now (but do learn to use them eventually, as they are extremely cool!).