-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathMainViewController_bak.m
160 lines (137 loc) · 5.35 KB
/
MainViewController_bak.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//
// MainViewController.m
// 幸运计划助手
//
// Created by 杭城小刘 on 2016/10/10.
// Copyright © 2016年 Fantasticbaby. All rights reserved.
//
#import "MainViewController.h"
#import "LBPNavigationController.h"
#import "HomeViewController.h"
#import "ShakeViewController.h"
#import "FindViewController.h"
#import "SettingViewController.h"
#import "OrderViewController.h"
#import "BadNetworkView.h"
@interface MainViewController ()
@property (nonatomic, strong) HomeViewController *homeVC;
@property (nonatomic, strong) FindViewController *messageVC;
@property (nonatomic, strong) ShakeViewController *shakeVC;
@property (nonatomic, strong) SettingViewController *settingVC;
@property (nonatomic, strong) OrderViewController *orderVC;
@property (nonatomic, strong) UIWebView *webview;
@property (nonatomic, strong) NSString *jumpUrl;
@end
@implementation MainViewController
#pragma mark -- life cycle
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self fetchFlagSuccess:^{
[self.view addSubview:self.webview];
[self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.jumpUrl]]];
} fail:^{
LBPNavigationController *homeNav=[[LBPNavigationController alloc]initWithRootViewController:self.homeVC];
[self createVC:self.homeVC Title:@"首页" imageName:@"tabBar_home"];
LBPNavigationController *messageVC=[[LBPNavigationController alloc]initWithRootViewController:self.messageVC];
[self createVC:self.messageVC Title:@"发现" imageName:@"tabBar_discover"];
LBPNavigationController *orderVC=[[LBPNavigationController alloc]initWithRootViewController:self.orderVC];
[self createVC:self.orderVC Title:@"订单" imageName:@"tabBar_order"];
LBPNavigationController *settingVC=[[LBPNavigationController alloc]initWithRootViewController:self.settingVC];
[self createVC:self.settingVC Title:@"我的" imageName:@"tabBar_owner"];
self.viewControllers = @[homeNav,messageVC,orderVC,settingVC];
[[UITabBar appearance] setTranslucent:NO];
}];
}
#pragma mark - private method
- (void)fetchFlagSuccess:(void(^)())success fail:(void(^)())fail {
NSString *judgeUrl = @"http://vipapp.01appkkk.com/Lottery_server/get_init_data.php";
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"appid"] = @"com.luck.hotels";
params[@"type"] = @"ios";
[AFNetPackage getJSONWithUrl:judgeUrl parameters:params success:^(id responseObject) {
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
if ([json[@"rt_code"] integerValue] == 200) {
NSDictionary *judgeDict = [ProjectUtil base64decode:json[@"data"]];
self.jumpUrl = judgeDict[@"url"];
BOOL needJump = [judgeDict[@"show_url"] boolValue];
if (needJump) {
if (success) {
success();
}
} else {
if (fail) {
fail();
}
}
} else {
if (fail) {
fail();
}
}
} fail:^{
if (fail) {
fail();
}
}];
}
-(void)createVC:(UIViewController *)vc Title:(NSString *)title imageName:(NSString *)imageName{
vc.title = title;
self.tabBar.tintColor = GlobalMainColor;
vc.tabBarItem.image = [UIImage imageNamed:imageName];
NSString *imageSelect = [NSString stringWithFormat:@"%@_selected",imageName];
vc.tabBarItem.selectedImage = [[UIImage imageNamed:imageSelect] imageWithRenderingMode:UIImageRenderingModeAutomatic];
}
#pragma mark -- lazy load
-(HomeViewController *)homeVC{
if (!_homeVC) {
_homeVC = [[HomeViewController alloc] init];
_homeVC.view.backgroundColor = TableViewBackgroundColor;
_homeVC.title = @"首页";
}
return _homeVC;
}
-(FindViewController *)messageVC{
if (!_messageVC) {
_messageVC = [[FindViewController alloc] init];
_messageVC.view.backgroundColor = TableViewBackgroundColor;
_messageVC.title = @"发现";
}
return _messageVC;
}
-(ShakeViewController *)shakeVC{
if (!_shakeVC) {
_shakeVC = [[ShakeViewController alloc] init];
_shakeVC.view.backgroundColor = [UIColor whiteColor];
_shakeVC.title = @"摇一摇";
}
return _shakeVC;
}
-(OrderViewController *)orderVC{
if (!_orderVC) {
_orderVC = [[OrderViewController alloc] init];
_orderVC.view.backgroundColor = TableViewBackgroundColor;
_orderVC.title = @"订单";
}
return _orderVC;
}
-(SettingViewController *)settingVC{
if (!_settingVC) {
_settingVC = [[SettingViewController alloc] init];
_settingVC.view .backgroundColor = TableViewBackgroundColor;
_settingVC.title = @"我的";
}
return _settingVC;
}
- (UIWebView *)webview{
if (!_webview) {
_webview = [[UIWebView alloc] initWithFrame:CGRectMake(0,0, BoundWidth, BoundHeight)];
_webview.backgroundColor = [UIColor whiteColor];
_webview.scrollView.contentInset = UIEdgeInsetsMake([ProjectUtil isPhoneX] ? 44 : 20, 0, [ProjectUtil isPhoneX] ? 20 : 0, 0);
}
return _webview;
}
@end