ios应用开发--判断用户是否已经登录

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 中添加

if ([self isUserLogin]) {

//添加主界面

        SPTabBarViewController *tabController = [[SPTabBarViewController alloc] init];

         tabController.view.frame = self.window.bounds;

        [UIView transitionWithView:self.window

                          duration:0.25

                           options:UIViewAnimationOptionTransitionCrossDissolve

                        animations:^{

                            self.window.rootViewController = tabController;

                        }

                        completion:nil];

    }else{

        //去登录界面

        self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

        UIViewController *controller = [[RaceLoginViewController alloc] init];

        self.window.rootViewController = controller;

        [self.window makeKeyAndVisible];

        

    }


判断方法

#pragma mark -- 是否登录

-(BOOL)isUserLogin

{

    NSString *userId =  [[NSUserDefaults standardUserDefaults]objectForKey:@"USER_ID"];

    

    if (userId != nil && [userId intValue] > 0)

    {

        //已经登录

        return YES;

    }

    return NO;

 


你可能感兴趣的:(ios应用开发--判断用户是否已经登录)