[iOS微博项目 - 2.4] - 重新安排app启动步骤

 
A.app启动步骤
1.加入了授权步骤之后,最先要判断app内是否已经登陆了账号
[iOS微博项目 - 2.4] - 重新安排app启动步骤
2.在程序启动的时候,先检测是否已有登陆账号
AppDelegate:
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch. // 启动后显示状态栏
UIApplication *app = [UIApplication sharedApplication];
app.statusBarHidden = NO; // 设置window
self.window = [[UIWindow alloc] init];
self.window.frame = [UIScreen mainScreen].bounds;
[self.window makeKeyAndVisible]; // 检查是否已有登陆账号
NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *filePath = [docPath stringByAppendingPathComponent:@"accountInfo.plist"];
NSDictionary *accountInfo = [NSDictionary dictionaryWithContentsOfFile:filePath]; if (!accountInfo) { // 如果不存在登陆账号,要先进行授权
self.window.rootViewController = [[HVWOAuthViewController alloc] init];
} else {
/** 新版本特性 */
// app现在的版本
// 由于使用的时Core Foundation的东西,需要桥接
NSString *versionKey = (__bridge NSString*) kCFBundleVersionKey;
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
NSString *currentVersion = [infoDic objectForKey:versionKey]; // 上次使用的版本
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *lastVersion = [defaults stringForKey:versionKey]; // 如果版本变动了,存储新的版本号并启动新版本特性图
if (![lastVersion isEqualToString:currentVersion]) { // 存储
[defaults setObject:currentVersion forKey:versionKey];
[defaults synchronize]; // 开启app显示新特性
HVWNewFeatureViewController *newFeatureVC = [[HVWNewFeatureViewController alloc] init];
self.window.rootViewController = newFeatureVC;
} else {
// 创建根控制器
HVWTabBarViewController *tabVC = [[HVWTabBarViewController alloc] init];
self.window.rootViewController = tabVC;
}
} return YES;
}
 
在授权控制器,授权完毕之后也要继续进入app:
 //  HVWOAuthViewController.m
/** 根据access_code获取access_token */
- (void) accessTokenWithAccessCode:(NSString *) accessCode {
// 创建AFN的http操作请求管理者
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; // 参数设置
NSMutableDictionary *param = [NSMutableDictionary dictionary];
param[@"client_id"] = @"";
param[@"client_secret"] = @"cc577953b2aa3aa8ea220fd15775ea35";
param[@"grant_type"] = @"authorization_code";
param[@"code"] = accessCode;
param[@"redirect_uri"] = @"http://www.cnblogs.com/hellovoidworld/"; // 发送请求
[manager POST:@"https://api.weibo.com/oauth2/access_token" parameters:param success:^(AFHTTPRequestOperation *operation, NSDictionary *accountInfo) {
[MBProgressHUD hideHUD]; // 返回的是用户信息字典
// 存储用户信息,包括access_token到沙盒中
NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *filePath = [docPath stringByAppendingPathComponent:@"accountInfo.plist"];
[accountInfo writeToFile:filePath atomically:YES]; /** 新版本特性 */
// app现在的版本
// 由于使用的时Core Foundation的东西,需要桥接
NSString *versionKey = (__bridge NSString*) kCFBundleVersionKey;
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
NSString *currentVersion = [infoDic objectForKey:versionKey]; // 上次使用的版本
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *lastVersion = [defaults stringForKey:versionKey]; UIWindow *window = [UIApplication sharedApplication].keyWindow; // 如果版本变动了,存储新的版本号并启动新版本特性图
if (![lastVersion isEqualToString:currentVersion]) {
// 存储
[defaults setObject:currentVersion forKey:versionKey];
[defaults synchronize]; // 开启app显示新特性
HVWNewFeatureViewController *newFeatureVC = [[HVWNewFeatureViewController alloc] init];
window.rootViewController = newFeatureVC;
} else {
// 创建根控制器
HVWTabBarViewController *tabVC = [[HVWTabBarViewController alloc] init];
window.rootViewController = tabVC;
} } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[MBProgressHUD hideHUD];
HVWLog(@"请求access_token失败 ----> %@", error);
}]; }
第一次启动:
需要授权+新特性显示
[iOS微博项目 - 2.4] - 重新安排app启动步骤
 
上一篇:Java中的Double类型计算


下一篇:ANDROID_MARS学习笔记_S01原始版_007_Handler及线程的简单使用