A.app启动步骤
1.加入了授权步骤之后,最先要判断app内是否已经登陆了账号
2.在程序启动的时候,先检测是否已有登陆账号
AppDelegate:
  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  2. // Override point for customization after application launch.
  3.  
  4. // 启动后显示状态栏
  5. UIApplication *app = [UIApplication sharedApplication];
  6. app.statusBarHidden = NO;
  7.  
  8. // 设置window
  9. self.window = [[UIWindow alloc] init];
  10. self.window.frame = [UIScreen mainScreen].bounds;
  11. [self.window makeKeyAndVisible];
  12.  
  13. // 检查是否已有登陆账号
  14. NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
  15. NSString *filePath = [docPath stringByAppendingPathComponent:@"accountInfo.plist"];
  16. NSDictionary *accountInfo = [NSDictionary dictionaryWithContentsOfFile:filePath];
  17.  
  18. if (!accountInfo) { // 如果不存在登陆账号,要先进行授权
  19. self.window.rootViewController = [[HVWOAuthViewController alloc] init];
  20. } else {
  21. /** 新版本特性 */
  22. // app现在的版本
  23. // 由于使用的时Core Foundation的东西,需要桥接
  24. NSString *versionKey = (__bridge NSString*) kCFBundleVersionKey;
  25. NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
  26. NSString *currentVersion = [infoDic objectForKey:versionKey];
  27.  
  28. // 上次使用的版本
  29. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  30. NSString *lastVersion = [defaults stringForKey:versionKey];
  31.  
  32. // 如果版本变动了,存储新的版本号并启动新版本特性图
  33. if (![lastVersion isEqualToString:currentVersion]) {
  34.  
  35. // 存储
  36. [defaults setObject:currentVersion forKey:versionKey];
  37. [defaults synchronize];
  38.  
  39. // 开启app显示新特性
  40. HVWNewFeatureViewController *newFeatureVC = [[HVWNewFeatureViewController alloc] init];
  41. self.window.rootViewController = newFeatureVC;
  42. } else {
  43. // 创建根控制器
  44. HVWTabBarViewController *tabVC = [[HVWTabBarViewController alloc] init];
  45. self.window.rootViewController = tabVC;
  46. }
  47. }
  48.  
  49. return YES;
  50. }
 
在授权控制器,授权完毕之后也要继续进入app:
  1. // HVWOAuthViewController.m
  2. /** 根据access_code获取access_token */
  3. - (void) accessTokenWithAccessCode:(NSString *) accessCode {
  4. // 创建AFN的http操作请求管理者
  5. AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
  6.  
  7. // 参数设置
  8. NSMutableDictionary *param = [NSMutableDictionary dictionary];
  9. param[@"client_id"] = @"";
  10. param[@"client_secret"] = @"cc577953b2aa3aa8ea220fd15775ea35";
  11. param[@"grant_type"] = @"authorization_code";
  12. param[@"code"] = accessCode;
  13. param[@"redirect_uri"] = @"http://www.cnblogs.com/hellovoidworld/";
  14.  
  15. // 发送请求
  16. [manager POST:@"https://api.weibo.com/oauth2/access_token" parameters:param success:^(AFHTTPRequestOperation *operation, NSDictionary *accountInfo) {
  17. [MBProgressHUD hideHUD];
  18.  
  19. // 返回的是用户信息字典
  20. // 存储用户信息,包括access_token到沙盒中
  21. NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
  22. NSString *filePath = [docPath stringByAppendingPathComponent:@"accountInfo.plist"];
  23. [accountInfo writeToFile:filePath atomically:YES];
  24.  
  25. /** 新版本特性 */
  26. // app现在的版本
  27. // 由于使用的时Core Foundation的东西,需要桥接
  28. NSString *versionKey = (__bridge NSString*) kCFBundleVersionKey;
  29. NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
  30. NSString *currentVersion = [infoDic objectForKey:versionKey];
  31.  
  32. // 上次使用的版本
  33. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  34. NSString *lastVersion = [defaults stringForKey:versionKey];
  35.  
  36. UIWindow *window = [UIApplication sharedApplication].keyWindow;
  37.  
  38. // 如果版本变动了,存储新的版本号并启动新版本特性图
  39. if (![lastVersion isEqualToString:currentVersion]) {
  40. // 存储
  41. [defaults setObject:currentVersion forKey:versionKey];
  42. [defaults synchronize];
  43.  
  44. // 开启app显示新特性
  45. HVWNewFeatureViewController *newFeatureVC = [[HVWNewFeatureViewController alloc] init];
  46. window.rootViewController = newFeatureVC;
  47. } else {
  48. // 创建根控制器
  49. HVWTabBarViewController *tabVC = [[HVWTabBarViewController alloc] init];
  50. window.rootViewController = tabVC;
  51. }
  52.  
  53. } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
  54. [MBProgressHUD hideHUD];
  55. HVWLog(@"请求access_token失败 ----> %@", error);
  56. }];
  57.  
  58. }
第一次启动:
需要授权+新特性显示
 

[iOS微博项目 - 2.4] - 重新安排app启动步骤的更多相关文章

  1. [iOS微博项目 - 3.0] - 手动刷新微博

    github: https://github.com/hellovoidworld/HVWWeibo   A.下拉刷新微博 1.需求 在“首页”界面,下拉到一定距离的时候刷新微博数据 刷新数据的时候使 ...

  2. [iOS微博项目 - 2.5] - 封装授权和用户信息读写业务

    github: https://github.com/hellovoidworld/HVWWeibo   A.封装授权业务 1.把app的授权信息移动到HVWWeibo-Prefix.pch中作为公共 ...

  3. [iOS微博项目 - 2.3] - 用户取消对app的授权

    github: https://github.com/hellovoidworld/HVWWeibo   A.用户取消对app的授权 用户可以在微博网站上取消对某个应用(app)的授权   1.打开& ...

  4. [iOS微博项目 - 2.2] - 在app中获取授权

    github: https://github.com/hellovoidworld/HVWWeibo   A.发送授权请求 1.使用UIWebView加载请求页面 自定义一个继承UIViewContr ...

  5. [iOS微博项目 - 2.6] - 获取微博数据

    github: https://github.com/hellovoidworld/HVWWeibo   A.新浪获取微博API 1.读取微博API     2.“statuses/home_time ...

  6. [iOS微博项目 - 2.0] - OAuth授权3步

    A.概念      OAUTH协议为用户资源的授权提供了一个安全的.开放而又简易的标准.与以往的授权方式不同之处是OAUTH的授权不会使第三方触及到用户的帐号信息(如用户名与密码),即第三方无需使用用 ...

  7. [iOS微博项目 - 1.7] - 版本新特性

    A.版本新特性 1.需求 第一次使用新版本的时候,不直接进入app,而是展示新特性界面 github: https://github.com/hellovoidworld/HVWWeibo       ...

  8. [iOS微博项目 - 1.0] - 搭建基本框架

    A.搭建基本环境   github: https://github.com/hellovoidworld/HVWWeibo   项目结构:   1.使用代码构建UI,不使用storyboard     ...

  9. [iOS微博项目 - 4.0] - 自定义微博cell

    github: https://github.com/hellovoidworld/HVWWeibo A.自定义微博cell基本结构 1.需求 创建自定义cell的雏形 cell包含:内容.工具条 内 ...

随机推荐

  1. js方式进行地理位置的定位api搜集

    新浪 //int.dpool.sina.com.cn/iplookup/iplookup.php?format=js //int.dpool.sina.com.cn/iplookup/iplookup ...

  2. mysql大数据导出导入

    1)导出 select * from users into outfile '/tmp/users.txt';或 select * from users where sex=1 into outfil ...

  3. Cmockery macro demo hacking

    /********************************************************************* * Cmockery macro demo hacking ...

  4. 【英语】Bingo口语笔记(10) - 常见词汇的缩读

  5. phonegap 单例模式

    今天在使用云推送的时候  app打开着,然后 控制台推送一条消息 结果点击后又重新打开了一个客户端... ok,我需要的是单例,我使用了singleInstance  ,达到了效果. 引用百度知道的 ...

  6. 通过外部接口 根据ip获取城市名

    3种接口 淘宝/百度/不知名/   推荐淘宝接口 ip自个去获取,下附带php 获取ip的示例 function getIP() { static $realip; if (isset($_SERVE ...

  7. UE删除空行

  8. IOS OC声明变量在@interface括号中与使用@property的区别(转载)

    刚开始接触OC再看别人写的代码的时候,常常困惑于人家在声明属性时的写法,总结出来有三中方式,不知道哪一种比较规范化,现在我把三种方式贴出来,然后再一一探讨每个方式声明属性的区别. 方式一:直接在@in ...

  9. 浅谈C#浅拷贝和深拷贝

    近来爱上一本书<编写高质量代码,改善C#程序的157个建议>,我想很多人都想编写高质量的代码,因为我们不仅仅是码农,更是一名程序员. 从今天开始,我将每天和大家分享这本书中的内容,并加上自 ...

  10. 什么是REST?以及RESTful的实现

    什么是REST? REST (REpresentation State Transfer) 描述了一个架构样式的网络系统,比如 web 应用程序.它首次出现在 2000 年 Roy Fielding ...