2013-07-03 67 views
-4

我希望在設備上的應用程序中,當用戶安裝應用程序時,用戶第一次用戶登錄後,將打開的應用程序和用戶保持登錄應該對他loginScreen有沒有什麼辦法,使這個保存,這樣,如果用戶再次打開應用第二則用戶應登錄陳述和不顯示用戶登錄屏幕感謝。如何請檢查是否應用程序是登錄或沒有第一次

- (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]; 

    } 

    [email protected]"Jamshaid"; 
    [email protected]"NO"; 
    [email protected]"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; 
} 
+0

但如何跟蹤記錄,它不應該用戶名稱一次又一次地 –

+0

如果應用程序啓動第一次,這意味着用戶沒有登錄,顯示出他的登錄界面。登錄後保存的用戶名在'NSUserDefault',當用戶在應用程序進入接下來的時間,以便檢查它在應用程序啓動第二次。 – TheTiger

+0

@TheTiger如果應用程序第一次運行,@TheTiger我已經給出我的代碼我將檢查登錄屏幕,然後我可以顯示登錄屏幕,但其他代碼在哪裏作爲碎末 –

回答

0

我不做iPhone的開發,但使用配置文件不會輕易實現嗎?例如:

  1. 應用程序啓動
  2. 閱讀config.xml中
  3. 是元素firstlogin或真或假?
    1. 如果爲true:顯示loginscreen,一旦用戶登錄,設置元素設置爲true,並保存XML。
    2. 如果假:完全不編輯XML和剛剛跳過loginscreen。
  4. 運行的應用程序

這,當然,復位,如果應用程序重新安裝,我的身影。

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"]; 
    } 
} 
相關問題