Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

newtoiphonesdk

macrumors 6502a
Original poster
Jul 30, 2010
567
2
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?
 
Last edited:

chown33

Moderator
Staff member
Aug 9, 2009
10,751
8,425
A sea of green
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.
 

newtoiphonesdk

macrumors 6502a
Original poster
Jul 30, 2010
567
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.

I added code for when currently is nil, and it still crashed.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
@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.
 

Ides

macrumors member
Mar 27, 2012
95
0
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.