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

- - (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;
- }
- // 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启动步骤的更多相关文章
- [iOS微博项目 - 3.0] - 手动刷新微博
github: https://github.com/hellovoidworld/HVWWeibo A.下拉刷新微博 1.需求 在“首页”界面,下拉到一定距离的时候刷新微博数据 刷新数据的时候使 ...
- [iOS微博项目 - 2.5] - 封装授权和用户信息读写业务
github: https://github.com/hellovoidworld/HVWWeibo A.封装授权业务 1.把app的授权信息移动到HVWWeibo-Prefix.pch中作为公共 ...
- [iOS微博项目 - 2.3] - 用户取消对app的授权
github: https://github.com/hellovoidworld/HVWWeibo A.用户取消对app的授权 用户可以在微博网站上取消对某个应用(app)的授权 1.打开& ...
- [iOS微博项目 - 2.2] - 在app中获取授权
github: https://github.com/hellovoidworld/HVWWeibo A.发送授权请求 1.使用UIWebView加载请求页面 自定义一个继承UIViewContr ...
- [iOS微博项目 - 2.6] - 获取微博数据
github: https://github.com/hellovoidworld/HVWWeibo A.新浪获取微博API 1.读取微博API 2.“statuses/home_time ...
- [iOS微博项目 - 2.0] - OAuth授权3步
A.概念 OAUTH协议为用户资源的授权提供了一个安全的.开放而又简易的标准.与以往的授权方式不同之处是OAUTH的授权不会使第三方触及到用户的帐号信息(如用户名与密码),即第三方无需使用用 ...
- [iOS微博项目 - 1.7] - 版本新特性
A.版本新特性 1.需求 第一次使用新版本的时候,不直接进入app,而是展示新特性界面 github: https://github.com/hellovoidworld/HVWWeibo ...
- [iOS微博项目 - 1.0] - 搭建基本框架
A.搭建基本环境 github: https://github.com/hellovoidworld/HVWWeibo 项目结构: 1.使用代码构建UI,不使用storyboard ...
- [iOS微博项目 - 4.0] - 自定义微博cell
github: https://github.com/hellovoidworld/HVWWeibo A.自定义微博cell基本结构 1.需求 创建自定义cell的雏形 cell包含:内容.工具条 内 ...
随机推荐
- js方式进行地理位置的定位api搜集
新浪 //int.dpool.sina.com.cn/iplookup/iplookup.php?format=js //int.dpool.sina.com.cn/iplookup/iplookup ...
- mysql大数据导出导入
1)导出 select * from users into outfile '/tmp/users.txt';或 select * from users where sex=1 into outfil ...
- Cmockery macro demo hacking
/********************************************************************* * Cmockery macro demo hacking ...
- 【英语】Bingo口语笔记(10) - 常见词汇的缩读
- phonegap 单例模式
今天在使用云推送的时候 app打开着,然后 控制台推送一条消息 结果点击后又重新打开了一个客户端... ok,我需要的是单例,我使用了singleInstance ,达到了效果. 引用百度知道的 ...
- 通过外部接口 根据ip获取城市名
3种接口 淘宝/百度/不知名/ 推荐淘宝接口 ip自个去获取,下附带php 获取ip的示例 function getIP() { static $realip; if (isset($_SERVE ...
- UE删除空行
- IOS OC声明变量在@interface括号中与使用@property的区别(转载)
刚开始接触OC再看别人写的代码的时候,常常困惑于人家在声明属性时的写法,总结出来有三中方式,不知道哪一种比较规范化,现在我把三种方式贴出来,然后再一一探讨每个方式声明属性的区别. 方式一:直接在@in ...
- 浅谈C#浅拷贝和深拷贝
近来爱上一本书<编写高质量代码,改善C#程序的157个建议>,我想很多人都想编写高质量的代码,因为我们不仅仅是码农,更是一名程序员. 从今天开始,我将每天和大家分享这本书中的内容,并加上自 ...
- 什么是REST?以及RESTful的实现
什么是REST? REST (REpresentation State Transfer) 描述了一个架构样式的网络系统,比如 web 应用程序.它首次出现在 2000 年 Roy Fielding ...