iOS判断是否登录 模型

登录判断模型
#import <Foundation/Foundation.h>

@interface LoginTool : NSObject
 
/**监测是否登录*/
+ (NSString *)getUid;
+ (NSString *)getUid:(BOOL)showMyViewController;
 
//获取uid
+ (void)setuid:(NSString *)uid;
@end
 
#import "LoginTool.h"
#import "MyViewController.h"
@implementation LoginTool

+(NSString *)getUid{

    NSString *uid = [[NSUserDefaults standardUserDefaults] stringForKey:@"uid"];
   
    MyViewController *myVC = [[MyViewController alloc]init];
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:myVC animated:YES completion:nil];
   
    return uid;

}

+ (void)setuid:(NSString *)uid{
   
    [[NSUserDefaults standardUserDefaults] setObject:uid forKey:@"uid"];
    [[NSUserDefaults standardUserDefaults]synchronize];

}

+ (NSString *)getUid:(BOOL)showMyViewController{
NSString *uid = [[NSUserDefaults standardUserDefaults] stringForKey:@"uid"];

    if (showMyViewController) {
        //延时加载0.1s
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1*NSEC_PER_SEC)),dispatch_get_main_queue(),^{
            MyViewController *myVC = [[MyViewController alloc]init];
            [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:myVC animated:YES completion:nil];
       
        });
    }
                       return uid;
}
@end
 
posted @ 2016-07-19 17:52  夜斗  阅读(188)  评论(0编辑  收藏  举报