Initial commit
This commit is contained in:
@@ -0,0 +1,323 @@
|
||||
//
|
||||
// SetViewController.m
|
||||
// Ifish
|
||||
//
|
||||
// Created by imac on 15/9/28.
|
||||
// Copyright © 2015年 imac. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SetViewController.h"
|
||||
#import "SetCell.h"
|
||||
#import "setModel.h"
|
||||
#import "DataCenter.h"
|
||||
#import "UserModel.h"
|
||||
#import "AFNetworking.h"
|
||||
#import "ChangeMobleController.h"
|
||||
#import "MyMD5.h"
|
||||
#import "ChangeSecretCodeController.h"
|
||||
#import "AboutUsViewController.h"
|
||||
//#import "LeftViewController.h"
|
||||
//#import "CenterViewController.h"
|
||||
#import "RegistViewController.h"
|
||||
#import "AppDelegate.h"
|
||||
#import "LogInViewController.h"
|
||||
#define TUICHUAlertTAg 4100
|
||||
#define BANBENAlertTAg 4110
|
||||
#import "DownLoadViewController.h"
|
||||
#import "Socketsingleton.h"
|
||||
@interface SetViewController ()<UITableViewDataSource,UITableViewDelegate,UIAlertViewDelegate>
|
||||
@property(nonatomic)Socketsingleton*singletonSocket;
|
||||
@end
|
||||
extern BOOL firstLogIn;
|
||||
@implementation SetViewController
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
[self ceratTableView];
|
||||
[self initData];
|
||||
[self setTitle];
|
||||
}
|
||||
-(void)setTitle{
|
||||
self.view.backgroundColor=COLOR_MIAN;
|
||||
[self addTitleViewWithTitle:@"设置"];
|
||||
|
||||
}
|
||||
-(void)initData{
|
||||
self.dataArr=@[@[@"更换手机",@"修改密码"],@[@"关于我们",@"当前版本"]];
|
||||
|
||||
}
|
||||
-(void)testVersion{
|
||||
UserModel*userModel=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"];
|
||||
// 替换手机号中间4位
|
||||
NSMutableString*string=[[NSMutableString alloc]initWithString:userModel.phoneNumber];
|
||||
[string replaceCharactersInRange:NSMakeRange(3, 4) withString:@"***"];
|
||||
self.telephone=[NSString stringWithFormat:@"当前绑定手机:%@",string];
|
||||
|
||||
//检测版本 post 请求
|
||||
AFHTTPRequestOperationManager*manager=[AFHTTPRequestOperationManager manager];
|
||||
manager.responseSerializer=[AFHTTPResponseSerializer serializer];
|
||||
[manager POST:kGetNewestVersion parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
||||
NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
|
||||
NSLog(@"result:%@",resultDic[@"result"]);
|
||||
|
||||
if ([resultDic[@"result"] isEqualToString:@"100"]) {
|
||||
|
||||
|
||||
NSDictionary*DataDic=resultDic[@"data"];
|
||||
NSString*version=DataDic[@"versionCode"];
|
||||
NSString*downloadAddress=DataDic[@"appAddress"];
|
||||
NSString*uploadContent=DataDic[@"uploadContent"];
|
||||
NSString*isMustUpdate=DataDic[@"isMustUpdate"];
|
||||
self.downloadAddress=downloadAddress;
|
||||
self.isMustUpdate=isMustUpdate;
|
||||
|
||||
if (![self.versionCode isEqualToString:version]) {
|
||||
if ([isMustUpdate isEqualToString:@"0"]) {
|
||||
UIAlertView*alertVew=[[UIAlertView alloc]initWithTitle:@"检测到新版本" message:uploadContent delegate:self cancelButtonTitle:@"暂不更新" otherButtonTitles:@"立即更新", nil];
|
||||
|
||||
alertVew.tag=BANBENAlertTAg;
|
||||
[alertVew show];
|
||||
}else{
|
||||
UIAlertView*alertVew=[[UIAlertView alloc]initWithTitle:@"检测到新版本" message:uploadContent delegate:self cancelButtonTitle:nil otherButtonTitles:@"立即更新", nil];
|
||||
|
||||
alertVew.tag=BANBENAlertTAg;
|
||||
[alertVew show];
|
||||
}
|
||||
|
||||
|
||||
}else{
|
||||
|
||||
[self showTitle:@"" messsage:@"未检测到新版本"];
|
||||
}
|
||||
|
||||
}else if ([resultDic[@"result"] isEqualToString:@"101"]){
|
||||
|
||||
}else if ([resultDic[@"result"] isEqualToString:@"101"]){
|
||||
|
||||
}else if ([resultDic[@"result"] isEqualToString:@"301"]){
|
||||
|
||||
}else if ([resultDic[@"result"] isEqualToString:@"302"]){
|
||||
|
||||
}
|
||||
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
||||
|
||||
}];
|
||||
}
|
||||
-(void)ceratTableView{
|
||||
_tableVIew=[[UITableView alloc]init];
|
||||
_tableVIew.frame=self.view.bounds;
|
||||
_tableVIew.delegate=self;
|
||||
_tableVIew.dataSource=self;
|
||||
_tableVIew.separatorStyle=UITableViewCellSeparatorStyleNone;
|
||||
_tableVIew.scrollEnabled=YES;
|
||||
|
||||
_tableVIew.backgroundColor=COLOR_MIAN;
|
||||
_tableVIew.bounces=NO;
|
||||
self.automaticallyAdjustsScrollViewInsets =YES;
|
||||
|
||||
[self.view addSubview:self.tableVIew];
|
||||
}
|
||||
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
|
||||
|
||||
return 2;
|
||||
}
|
||||
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
||||
|
||||
return 2;
|
||||
|
||||
|
||||
}
|
||||
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
||||
|
||||
|
||||
SetCell*cell=[tableView dequeueReusableCellWithIdentifier:@"SetCell"];
|
||||
setModel *model=[[setModel alloc]init];
|
||||
|
||||
if (cell==nil) {
|
||||
|
||||
cell= [[[NSBundle mainBundle]loadNibNamed:@"SetCell" owner:self options:nil]lastObject];
|
||||
}
|
||||
cell.accessoryType=UITableViewCellAccessoryNone;
|
||||
|
||||
|
||||
model.title=self.dataArr[indexPath.section][indexPath.row];
|
||||
cell.titlelabel.text=model.title;
|
||||
|
||||
|
||||
model.setDetail=self.setArr[indexPath.section][indexPath.row];
|
||||
cell.setLabel.text=model.setDetail;
|
||||
[cell resetCellbackImgAt:indexPath];
|
||||
|
||||
return cell;
|
||||
}
|
||||
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
|
||||
|
||||
return 60;
|
||||
}
|
||||
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
|
||||
// [tableView deselectRowAtIndexPath:indexPath animated:YES]; //取消选中状态
|
||||
if (indexPath.row==0&&indexPath.section==0) {
|
||||
ChangeMobleController*changeVC=[[ChangeMobleController alloc]init];
|
||||
|
||||
[self.navigationController pushViewController:changeVC animated:YES];
|
||||
}else if (indexPath.row==1&&indexPath.section==0){
|
||||
ChangeSecretCodeController *secretVC=[[ChangeSecretCodeController alloc]init];
|
||||
[self.navigationController pushViewController:secretVC animated:YES];
|
||||
}else if (indexPath.row==0&&indexPath.section==1){
|
||||
AboutUsViewController*usVC=[[AboutUsViewController alloc]init];
|
||||
[self.navigationController pushViewController:usVC animated:YES];
|
||||
}else if (indexPath.row==1&&indexPath.section==1){
|
||||
//[self testVersion];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
|
||||
return 10 ;
|
||||
}
|
||||
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
|
||||
if (section==1) {
|
||||
return kScreenSize.height-64-20*3-60*5;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
|
||||
UIView*headerView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenSize.width, 20)];
|
||||
headerView.backgroundColor=COLOR_MIAN;
|
||||
return headerView;
|
||||
|
||||
}
|
||||
-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
|
||||
UIView*footView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenSize.width, kScreenSize.height-64-20*3-60*5)];
|
||||
footView.backgroundColor=COLOR_MIAN;
|
||||
|
||||
if (section ==1) {
|
||||
UIButton *tuiChuBtn=[UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[tuiChuBtn setTitle:@"退 出" forState:UIControlStateNormal];
|
||||
[tuiChuBtn addTarget:self action:@selector(tuiChuAction:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[tuiChuBtn setTintColor:[UIColor whiteColor]];
|
||||
tuiChuBtn.backgroundColor=[UIColor colorWithRed:255.0/255.0f green:71.0/255.0f blue:71.0/255.0f alpha:1];
|
||||
tuiChuBtn.layer.masksToBounds = YES;
|
||||
tuiChuBtn.layer.cornerRadius = 5;
|
||||
|
||||
tuiChuBtn.frame=CGRectMake(10, 20, kScreenSize.width - 10 * 2, 60);
|
||||
|
||||
[footView addSubview:tuiChuBtn];
|
||||
|
||||
}
|
||||
return footView;
|
||||
|
||||
}
|
||||
|
||||
#pragma mark 退出按钮点击事件
|
||||
|
||||
-(void)tuiChuAction:(UIButton*)brtn{
|
||||
UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@"提醒" message:@"确认退出?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
|
||||
alert.tag=TUICHUAlertTAg;
|
||||
[alert show];
|
||||
|
||||
}
|
||||
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
|
||||
// if (buttonIndex==1) {
|
||||
switch (alertView.tag) {
|
||||
case TUICHUAlertTAg:
|
||||
{
|
||||
if (buttonIndex==1) {
|
||||
|
||||
_singletonSocket=[Socketsingleton sharedInstance];
|
||||
[_singletonSocket cutOffSocket];
|
||||
//切换 时重置标志位
|
||||
NSUserDefaults*userdefult=[NSUserDefaults standardUserDefaults];
|
||||
NSInteger index=0;
|
||||
[userdefult setInteger:index forKey:@"lastIndex"];
|
||||
|
||||
[userdefult setObject:@"1" forKey:@"isExit"];
|
||||
[userdefult setObject:nil forKey:@"password"];
|
||||
|
||||
[userdefult setObject:nil forKey:@"cameralastIndex"];
|
||||
|
||||
[userdefult synchronize];
|
||||
|
||||
UIApplication*app=[UIApplication sharedApplication];
|
||||
AppDelegate*app1=app.delegate;
|
||||
// RegistViewController*registViewController=[[RegistViewController alloc]init];// 切换导航
|
||||
LogInViewController*logIn=[[LogInViewController alloc]init];
|
||||
|
||||
UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:logIn];
|
||||
[nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"blackbar.png"] forBarMetrics:UIBarMetricsDefault];
|
||||
app1.window.rootViewController=nav;
|
||||
|
||||
firstLogIn=NO;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case BANBENAlertTAg:
|
||||
{
|
||||
if ([self.isMustUpdate isEqualToString:@"0"]) {
|
||||
if (buttonIndex==1) {
|
||||
//非强制更新
|
||||
[self initDownLoadView];
|
||||
}
|
||||
}else{
|
||||
// 强制更新
|
||||
if (buttonIndex==0) {
|
||||
[self initDownLoadView];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
-(void)initDownLoadView{
|
||||
DownLoadViewController*downVC=[[DownLoadViewController alloc]init];
|
||||
downVC.downAddress=self.downloadAddress;
|
||||
downVC.fromsetView=YES;
|
||||
if ([self.isMustUpdate isEqualToString:@"1"]) {
|
||||
downVC.ismust=YES;
|
||||
}else{
|
||||
downVC.ismust=NO;
|
||||
|
||||
}
|
||||
|
||||
[self.navigationController pushViewController:downVC animated:YES];
|
||||
|
||||
}
|
||||
|
||||
-(void)viewWillAppear:(BOOL)animated{
|
||||
// if 更换手机 更新手机号
|
||||
UserModel*userModel=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"];
|
||||
if (userModel.phoneNumber==nil) {
|
||||
[self showTitle:@"" messsage:@"服务器挂掉"];
|
||||
}else{
|
||||
|
||||
NSMutableString*string=[[NSMutableString alloc]initWithString:userModel.phoneNumber];
|
||||
[string replaceCharactersInRange:NSMakeRange(3, 4) withString:@"***"];
|
||||
self.telephone=[NSString stringWithFormat:@"当前绑定手机:%@",string];
|
||||
//版本
|
||||
NSUserDefaults*userdefult=[NSUserDefaults standardUserDefaults];
|
||||
NSString*curentVersion=[userdefult objectForKey:@"Version"];
|
||||
|
||||
self.versionCode=curentVersion;
|
||||
|
||||
NSString*verionString=[NSString stringWithFormat:@"当前版本%@",self.versionCode];
|
||||
// NSUserDefaults*userdefult=[NSUserDefaults standardUserDefaults];
|
||||
// NSString*version=@"";
|
||||
self.setArr=@[@[self.telephone,@"修改登录密码"],@[@"爱奇鱼团队",verionString]];
|
||||
self.navigationController.navigationBarHidden=NO;
|
||||
}
|
||||
}
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
|
||||
}
|
||||
@end
|
||||
Reference in New Issue
Block a user