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

    }

    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;
}
4

2 回答 2

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"];
    }
}
于 2013-07-03T09:18:14.370 回答
0

我不做 iPhone 开发,但是这不是很容易使用配置文件来实现的吗?例如:

  1. 应用启动
  2. 读取 config.xml
  3. 元素是firstlogin假的还是真的?
    1. 如果为真:显示登录屏幕,一旦用户登录,将元素设置为真并保存 xml。
    2. 如果为假:根本不编辑 xml 并跳过登录屏幕。
  4. 运行应用

我想,如果重新安装应用程序,这当然会重置。

于 2013-07-03T07:48:18.057 回答