您的位置:首页 > 移动开发 > IOS开发

iOS --------- 强制提示用户版本升级

2015-11-17 15:11 465 查看
//

// LoginAnRegisterViewController.m

// HengTaiXinGolf

//

// Created by ouyangrong on 15/7/15.

// Copyright (c) 2015年 HengTaiXinGolf. All rights reserved.

//

#import "LoginAnRegisterViewController.h"

#import "MyLoginViewController.h"

#import "MyRegisterViewController.h"

@interface
LoginAnRegisterViewController ()<UIAlertViewDelegate>

@end

@implementation LoginAnRegisterViewController

{

NSString *appVersion;

}

- (void)viewDidLoad {

[super
viewDidLoad];

// Do any additional setup after loading the view.

[self
versionButton];

[self
creatLoginAndRegisterView];

}

//城市高尔夫版本更新实现方法

-(void)versionButton{

//获取发布版本的version

NSString *string = [NSString
stringWithContentsOfURL:[NSURL
URLWithString:ITUNESLOOKUPURL]
encoding:NSUTF8StringEncoding
error:nil];

if (string !=
nil && [string length] >
0 && [string rangeOfString:@"version"].length ==
7) {

// NSLog(@"------版本号2--------------%@",string);

[self checkAppUpdate:string];

}

}

#pragma mark --------比较当前版本与新上线版本做比较

-(void)checkAppUpdate:(NSString *)appInfo{

//获取当前版本

NSString *version = [[NSBundle
mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];

//构建版本

// NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];

NSString *appInfo1 = [appInfo
substringFromIndex:[appInfo rangeOfString:@"\"version\":"].location +
10];

appInfo1 = [[appInfo1 substringToIndex:[appInfo1
rangeOfString:@","].location]stringByReplacingOccurrencesOfString:@"\""
withString:@""];

//判断,如果当前版本与发布版本不相同,则进入更新;如果相等,那么当前就是最高版本

// NSLog(@"------------新版本:%@,----------------当前版本:%@",appInfo1,version);

appVersion = appInfo1;

if (![appInfo1
isEqualToString:version]) {

UIAlertView *alert = [[UIAlertView
alloc]initWithTitle:@"提示"
message:[NSString
stringWithFormat:@"《城市高尔夫》有新的版本%@,点击到AppStore升级新版本!",appVersion]
delegate:self
cancelButtonTitle:@"知道了"
otherButtonTitles:nil,nil];

alert.delegate =
self;

[alert addButtonWithTitle:@"前往更新"];

[alert show];

alert.tag =
20;

//

// UILocalNotification *localNotification = [[UILocalNotification alloc]init];

// if (localNotification) {

// //
设置通知的提醒时间

//// NSDate *date = [NSDate dateWithTimeIntervalSinceNow:3];

//// localNotification.fireDate = date;

// //
设置通知的提醒时间

// NSDate *currentDate = [NSDate date];

// //设置时区

// localNotification.timeZone = [NSTimeZone defaultTimeZone]; //
使用本地时区

// localNotification.fireDate = [currentDate dateByAddingTimeInterval:5.0];

// //设置重复间隔

// localNotification.repeatInterval = NSCalendarUnitWeekOfMonth;

//

//// localNotification.fireDate = [[[NSDate alloc]init]dateByAddingTimeInterval:3];

//// NSTimeZone*zone=[[NSTimeZone alloc]initWithName:@"GMT+8"];

// //设置提醒文字内容

// localNotification.alertBody = @"城市高尔夫有新的版本,点击到AppStore升级。";

// localNotification.alertAction = @"升级";

// //通知提示音
使用默认的

// localNotification.soundName = UILocalNotificationDefaultSoundName;

//// [application scheduleLocalNotification:localNotification];

//// NSMutableDictionary *aUserInfo = [[NSMutableDictionary alloc]init];

//// aUserInfo[kLocalNotificationID] = @"LocalNotificationID";

// NSDictionary *infoDic = [NSDictionary dictionaryWithObject:@"LocalNotificationID" forKey:@"key"];

// localNotification.userInfo = infoDic;

//

// // ios8后,需要添加这个注册,才能得到授权

//

// if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {

// UIUserNotificationType type = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound;

// UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:type

// categories:nil];

// [[UIApplication sharedApplication] registerUserNotificationSettings:settings];

// }

//

// UIApplication *app = [UIApplication sharedApplication];

// [app scheduleLocalNotification:localNotification];

//

//

// }

}else{

// UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"已是最高版本"
delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];

// [alert show];

NSLog(@"已是最高版本!");

}

}

#pragma mark---------UIAlertView
代理方法

-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{

if (buttonIndex ==
1 && alertView.tag ==
20) {

[[UIApplication
sharedApplication] openURL:[NSURL
URLWithString:ITUNESLOADURL]];

}

}

//创建启动登录注册界面

-(void)creatLoginAndRegisterView{

UIImageView *imgView = [[UIImageView
alloc]initWithFrame:CGRectMake(0,
0, IPHONE_WIDTH,
IPHONE_HEIGHT)];

imgView.image = [UIImage
imageNamed:@"qdtp"];

[self.view
addSubview:imgView];

//登录按钮

UIButton *longinBtn = [UIButton
buttonWithType:UIButtonTypeCustom];

longinBtn.frame =
CGRectMake(20,
IPHONE_HEIGHT-100,
IPHONE_WIDTH/2-40,
40);

longinBtn.backgroundColor =
kColor(1, 143,
227);

[longinBtn setTitle:@"登录"
forState:UIControlStateNormal];

longinBtn.clipsToBounds=
YES;

longinBtn.layer.cornerRadius=
4;

[longinBtn addTarget:self
action:@selector(longinBtnClick)
forControlEvents:UIControlEventTouchUpInside];

[self.view
addSubview:longinBtn];

//注册按钮

UIButton *registerBtn = [UIButton
buttonWithType:UIButtonTypeCustom];

registerBtn.frame =
CGRectMake(IPHONE_WIDTH/2 +
20,
IPHONE_HEIGHT-100,
IPHONE_WIDTH/2-40,
40);

registerBtn.backgroundColor =
kColor(1, 143,
227);

registerBtn.clipsToBounds=YES;

registerBtn.layer.cornerRadius=4;

[registerBtn setTitle:@"注册"
forState:UIControlStateNormal];

[registerBtn addTarget:self
action:@selector(registerBtnClick)
forControlEvents:UIControlEventTouchUpInside];

[self.view
addSubview:registerBtn];

}

//进入登录界面

-(void)longinBtnClick{

NSLog(@"进入登录界面");

// ModalView* modalView2 = [[ModalView alloc] init];

// UIViewController* presentingViewController = self.presentingViewController;

// [self dismissViewControllerAnimated:YES completion:^{

// [presentingViewController presentViewController:modalView2 animated:YES completion:nil];

MyLoginViewController *myLVC = [[MyLoginViewController
alloc]init];

// [self dismissViewControllerAnimated:NO completion:nil];

// myLVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

// UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:myLVC];

[self
presentViewController:myLVC animated:NO
completion:^{

// [self.view removeFromSuperview];

}];

}

//进入注册界面

-(void)registerBtnClick{

NSLog(@"进入注册界面");

MyRegisterViewController *myRVC = [[MyRegisterViewController
alloc]init];

// myRVC.modalTransitionStyle = UIModalTransitionStylePartialCurl;

[self
presentViewController:myRVC animated:NO
completion:^{

}];

}

- (void)didReceiveMemoryWarning {

[super
didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

- (BOOL)shouldAutorotate

{

return
YES;

}

- (NSUInteger)supportedInterfaceOrientations

{

return
UIInterfaceOrientationMaskPortrait;

}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

{

return
UIInterfaceOrientationPortrait;

}

/*

#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

// Get the new view controller using [segue destinationViewController].

// Pass the selected object to the new view controller.

}

*/

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: