开发者

My iOS App Works Well In The Simulator, But Not In A Real Device?

开发者 https://www.devze.com 2023-02-23 15:02 出处:网络
So my first app I am making is for jailbroken devices. I must say it\'s not finished yet, but I believe it\'s a good habit to test incomplete apps in a real device every now and then while developing

So my first app I am making is for jailbroken devices.

I must say it's not finished yet, but I believe it's a good habit to test incomplete apps in a real device every now and then while developing the app. Since my app is for jailbroken devices, I have to fake sign the app and all that.

The thing is, my app has a plist with two entries: a bool for "hasBeenLaunchedBefore" and a string for "Password". My app changes TRUE to hasBeenLaunchedBefore when the app is finished configuring, so when the app loads it gets a different view. The password is straightforward: it stores a password for the user.

I think my plist file is not getting modified when I launch my app in my device, because well, when the app has never launched before, you get a configuration wizard. Everytime I close the app I keep getting the config wizard, which means hasBeenLaunchedBefore is not changed to TRUE as it is supposed be. Also, my passwords NEVER match, so it means the password doesn't get modified either.

Everything works fine in the iOS Simulator, but not in my iDevice. Could someone help me a bit with this? Could it be a permissio开发者_开发问答ns issue? This has really, really left me with no words or ideas to fix it. I am guessing I could put the plist in /Documents, but I have no idea of how to do that. So if anyone has suggestions for me to fix this, I will highly appreciate it.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

// Override point for customization after application launch.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if(![defaults objectForKey:@"first_launch"]){ //Load first_launch from NSUserDefaults. It should be either true or false, but never (null).
    [self.window addSubview:configWizard.view];
    UIAlertView *lol = [[UIAlertView alloc] initWithTitle:@"Never started before." message:@"The app was never started before." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [lol show];
    [lol release];
}else{
    [self.window addSubview:tabBarController.view];
    UIAlertView *lol = [[UIAlertView alloc] initWithTitle:@"Started before." message:@"The app was started before." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [lol show];
    [lol release];
}

[defaults synchronize];

// Add the tab bar controller's view to the window and display.
[self.window makeKeyAndVisible];

return YES;

}

That's the old code I was using when I attempted to load from NSUserDefaults, but first_launch kept returning (null).


Hmm. App's behaviour on a device and in simulator is different. So your ideas about testing are quite right. I don't now exactly (bad, but honestly))), but I'm quite agree with your supposition that problem is in file permissions.

As a solution I can suggest to use NSUserDefaults. Moveover, working with them in this situation should be easier.

UPDATE

Try this:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (![defaults boolForKey:@"first_launch"]) {       // use boolForKey instead objectForKey here
     [defaults setBool:YES forKey:@"first_launch"];     // change the value (next time launch is not the first one)
     [defaults synchronize];    // you should synchronize only if values were changed

     UIAlertView *lol = [[UIAlertView alloc] initWithTitle:@"Never started before."
            message:@"The app was never started before." delegate:nil
            cancelButtonTitle:@"OK" otherButtonTitles:nil];
     [lol show];
     [lol release];
} else {
     UIAlertView *lol = [[UIAlertView alloc] initWithTitle:@"Started before."
            message:@"The app was started before." delegate:nil
            cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [lol show];
    [lol release];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消