检测版本更新
来源:互联网 发布:淘宝网首页不显示图片 编辑:程序博客网 时间:2024/06/14 00:18
@interfaceViewController ()<UIAlertViewDelegate>
{
NSString *updateURL;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[superviewDidLoad];
[selfisNewestVersion];
[selfperformSelector:@selector(donghua)withObject:selfafterDelay:0.1];
}
- (void)isNewestVersion
{
updateURL =@"";
[NSURLConnectionsendAsynchronousRequest:[NSURLRequestrequestWithURL:[NSURLURLWithString:@“”]]queue:[NSOperationQueuecurrentQueue]completionHandler:^(NSURLResponse *response,NSData *data,NSError *connectionError) {
if (data) {
NSArray *result= [NSJSONSerializationJSONObjectWithData:data options:0 error:nil];
// NSLog(@"result = %@", result);
//对比版本
// NSString * version=result[@"version"];
//对应 CFBundleVersion,对应Xcode项目配置"General"中的 Build
// NSString * versionShort=result[@"versionShort"];
//对应 CFBundleShortVersionString,对应Xcode项目配置"General"中的 Version
NSString *versionShort = [result[0]objectForKey:@"versionShort"];
// NSString * localVersion=[[NSBundle mainBundle] infoDictionary][@"CFBundleVersion"];
NSString * localVersionShort=[[NSBundlemainBundle] infoDictionary][@"CFBundleShortVersionString"];
// NSString *url=result[@"update_url"]; //如果有更新需要用Safari打开的地址
// NSString *changelog=result[@"changelog"]; //如果有更新需要用Safari打开的地址
//这里放对比版本的逻辑 每个 app 对版本更新的理解都不同
//有的对比 version,有的对比 build[version isEqualToString:localVersion]
if ([versionShort isEqualToString:localVersionShort]) {
return ;
}else {
// 去更新
UIAlertView *alView = [[UIAlertViewalloc]initWithTitle:@"提示"message:@"检测到新版本,去更新么?"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"更新",nil];
alView.delegate =self;
[alViewshow];
}
}
}];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == alertView.cancelButtonIndex) {
return;
}else {
[selfgotoDownLoadNeWVersion];
}
}
- (void)gotoDownLoadNeWVersion
{
NSURL* url = [[NSURLalloc] initWithString:updateURL];
[[ UIApplicationsharedApplication]openURL:url];
}
@end
- 版本更新检测
- iOS 检测版本更新
- Android 检测版本更新
- iOS 检测版本更新
- IOS检测版本更新
- iOS检测版本更新
- iOS 检测版本更新
- iOS 检测版本更新
- IOS 版本更新检测
- iOS 检测版本更新
- iOS 检测版本更新
- iOS --检测更新版本
- 检测版本更新
- ios检测版本更新
- iOS 检测版本更新
- iOS 检测版本更新
- iOS 检测版本更新
- iOS 检测版本更新
- PHP生成PDF文件
- 帮Facebook把用户做到7亿 他只做了三件事
- Android Studio奇技淫巧一览 大幅度提升工作效率
- Mr. Process的一生-Linux内核的社会视角 (1) 调度
- TextView和EditText的显示
- 检测版本更新
- webservice编程中的RPCServiceClient类在哪个jar包中?
- Ajax适用场景
- UVO 120 Stacks of Flapjacks (整行输入+构造函数)
- linux 共享库的编译和连接
- [LeedCode OJ]#162 Find Peak Element
- Axis 2 客户端必须的一些包
- BLToolkit: Sogen - Code generator for BLToolkit
- 使用jquery.cookie.js实现记住用户信息(下面以web的记住登录名和密码为例进行说明)