Update to my app causing crash

Discussion in 'iOS Programming' started by newtoiphonesdk, Dec 1, 2012.

  1. newtoiphonesdk, Dec 1, 2012
    Last edited: Dec 1, 2012

    newtoiphonesdk macrumors 6502a

    Joined:
    Jul 30, 2010
    #1
    I wanted the app to ask a question the first time, and ONLY the first time the app was ran, so in the AppDelegate didFinishLaunchingWithOptions I have:

    Code:
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if (! [defaults boolForKey:@"notFirstRun"]) {
        UIAlertView *firstrun = [[UIAlertView alloc] initWithTitle:@"Sermon Preference" message:@"Do you prefer audio only, or video sermons?  (This setting can be changed at any time in the Settings Page.)" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Audio", @"Video", nil];
            [firstrun show];
            [firstrun release];
        [defaults setBool:YES forKey:@"notFirstRun"];
    }
    Then I have in the AppDelegate Still:

    Code:
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
            if (buttonIndex == 0)       {   
                NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
                NSString *nope = @"Audio";
                [defaults setObject:nope forKey:@"videosermons"];
                [defaults synchronize];
    
    
            }
            if (buttonIndex == 1)        {
                NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
                NSString *yup = @"Video";
                [defaults setObject:yup forKey:@"videosermons"];
                [defaults synchronize];        }
    
            }
    I wanted these values to be changed in a Settings window, so in the Settings class I have:

    Code:
    - (void)viewDidLoad
    {
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
    
            NSString *currently = [defaults objectForKey:@"videosermons"];
    
        if ([currently isEqualToString:@"Audio"]) {
            segment.selectedSegmentIndex = 0;
        }
        if ([currently isEqualToString:@"Video"]) {
            segment.selectedSegmentIndex = 1;
        }
    
    
        NSString *firstName = [defaults objectForKey:@"firstName"];
        if (firstName  == nil) {
    
        }
        else {
            myTextField.text = firstName;
        }
        NSURL *url = [NSURL URLWithString:@"http://www.bellavenue.org/worship.html"];
        self.content = [NSString stringWithContentsOfURL:url];
        [super viewDidLoad];
    }
    The line that the crash log says is causing the crash is:

    Code:
    if ([currently isEqualToString:@"Audio"]) {
    I'm assuming it has something to do with the notFirstRun Bool in AppDelegate, but can't get my finger on it. What do you think the issue may be?
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    What would you expect to happen when 'currently' is nil?

    If you can't work it out by thinking it through, set a breakpoint on the method that crashes, and step through line by line.
     
  3. newtoiphonesdk thread starter macrumors 6502a

    Joined:
    Jul 30, 2010
    #3
    I added code for when currently is nil, and it still crashed.
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    Post your code.

    Identify the line that crashes.

    Did you set a breakpoint and use the debugger to step?
     
  5. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #5
    @OP, what does "crash" mean? What appears in the debugger console?

    BTW, you'll find that setting a bool for firstRun isn't as useful as setting a version number for the app. In a later release you'll want a new firstRun action. Comparing the version number will usually be more useful.
     
  6. Ides macrumors member

    Joined:
    Mar 27, 2012
    #6
    Yes, please post what the crash log in the Xcode debugger actually says, it will make things go a lot faster. As far as I can see, the only reason that the line of code you're referring to should cause a crash is if "currently" is not actually an NSString object.

    Another suggestion, before the line that causes a crash, put in this line:

    Code:
    NSLog( @"%@", currently );
    And post what that says.
     

Share This Page