如何检查应用程序是否第一次登录

时间:2013-07-03 07:44:13

标签: iphone ios login

我希望用户在设备应用程序上安装应用程序时应该在用户第一次打开应用程序后显示登录屏幕,用户登录后用户保持登录是否有任何方法进行此保存,以便如果用户再次打开应用程序第二,那么用户应该处于记录状态并且不向用户显示登录屏幕谢谢。

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

    // Override point for customization after app launch.
    self.splitViewController =[[UISplitViewController alloc]init];
    self.rootViewController=[[RootViewController alloc]init];
    self.detailViewController=[[[FirstDetailViewController alloc]init] autorelease];
    self.loginViewController=[[[LoginViewController alloc]init] autorelease];

    UINavigationController *rootNav=[[UINavigationController alloc]initWithRootViewController:rootViewController];
    UINavigationController *detailNav=[[UINavigationController alloc]initWithRootViewController:detailViewController];

    if ([detailNav.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) 
    {
        UIImage *image = [UIImage imageNamed:@"Nav.png"];
        [detailNav.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

    }

    user_Name=@"Jamshaid";
    isClickedLogin=@"NO";
    userLogin=@"Logout";

    self.splitViewController.viewControllers=[NSArray arrayWithObjects:rootNav,detailNav,nil];
    self.splitViewController.delegate=self.detailViewController;

    NSMutableArray *tempArray = [[NSMutableArray alloc] init];
    self.coffeeArray = tempArray;
    [tempArray release];

    NSMutableArray *tempArray1 = [[NSMutableArray alloc] init];
    self.arrayOne = tempArray1;
    [tempArray1 release];

    NSMutableArray *tempArray2 = [[NSMutableArray alloc] init];
    self.arrayTwo = tempArray2;
    [tempArray2 release];

    NSMutableArray *tempArray3 = [[NSMutableArray alloc] init];
    self.libraryArray = tempArray3;
    [tempArray3 release];

    NSMutableArray *tempArray4 = [[NSMutableArray alloc] init];
    self.activityArray = tempArray4;
    [tempArray4 release];

    NSMutableArray *tempArray5 = [[NSMutableArray alloc] init];
    self.arrayOneC = tempArray5;
    [tempArray5 release];

    NSMutableArray *tempArray6 = [[NSMutableArray alloc] init];
    self.arrayTwoC = tempArray6;
    [tempArray6 release];

    NSMutableArray *tempArrayD = [[NSMutableArray alloc] init];
    self.detailArray = tempArrayD;
    [tempArrayD release];

    NSMutableArray *tempArrayD1 = [[NSMutableArray alloc] init];
    self.detailArrayOne = tempArrayD1;
    [tempArrayD1 release];

    NSMutableArray *tempArrayD2 = [[NSMutableArray alloc] init];
    self.detailArrayTwo = tempArrayD2;
    [tempArrayD2 release];

    NSMutableArray *tempArrayD3 = [[NSMutableArray alloc] init];
    self.publishArray = tempArrayD3;
    [tempArrayD3 release];

    [Coffee getInitialDataToDisplay:[self getDBPath]];

    // Add the split view controller's view to the window and display.
    // original working [window addSubview:self.splitViewController.view];
    [window addSubview:splitViewController.view];
    [window makeKeyAndVisible];

    return YES;
}

2 个答案:

答案 0 :(得分:0)

我不进行iPhone开发,但是使用配置文件不容易实现吗?例如:

  1. App start
  2. read config.xml
  3. 是元素firstlogin是假还是真?
    1. 如果为true:显示登录屏幕,一旦用户登录,将element设置为true并保存xml。
    2. 如果为false:根本不编辑xml,只需跳过登录屏幕。
  4. 运行应用
  5. 当然,如果应用程序重新安装,这将会重置,我想。

答案 1 :(得分:0)

示例代码:

yourViewController.h

NSString *uname;
NSString *pwd;

yourViewController.m

- (IBAction) loginButtonClicked :(id)sender
{
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
    {
        // app already launched
        uname = [[NSUserDefaults standardUserDefaults] valueForKey:@"UserName"];
        pwd = [[NSUserDefaults standardUserDefaults] valueForKey:@"PassWord"];
        //Use uname and pwd in your URL.
    }
    else
    {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        // This is the first launch ever
        [[NSUserDefaults standardUserDefaults] setValue:txtUserName.text forKey:@"UserName"];
        [[NSUserDefaults standardUserDefaults] setValue:txtPassWord.text forKey:@"PassWord"];
    }
}