当前位置: 移动技术网 > IT编程>移动开发>IOS > ios开发之应用程序检查更新功能实现方法

ios开发之应用程序检查更新功能实现方法

2018年03月17日  | 移动技术网IT编程  | 我要评论

平阳招生考试网,ku波段卫星,丁尚彪近况

ios开发之应用程序检查更新功能实现方法。

前几周,凡是包含了“检查更新”按钮的iOS应用程序均被拒绝上架了,探其原因,发现iOS8之后的系统都可以自动给应用程序升级。大概是苹果方面认为让软件开发商再做一个“检查更新”功能有点多余。不过站在程序员的角度上讲,“检查更新”功能被认为是用户使用次数最少,但偏偏pm们特别钟爱的一个功能。pm非要加,但苹果审核非要拒绝你的app,怎么办呢?其实,苹果现在还没有严苛到不能在程序中出现一丁点和检查更新功能的代码,经过我的大胆尝试,只要不把“检查更新”几个字显示出来就行。那。。。问题来了,没有这个按钮,该如何检查更新呢?傻呀~在app每启动一次,就去检查更新一次不就完了吗?哈哈哈哈,耍个小聪明,成功的将app上线了。

#pragmamark检查更新

-(void)onCheckVersion:(UIButton*)sender

{

_actV.hidden=NO;

NSDictionary*infoDic=[[NSBundlemainBundle]infoDictionary];

//CFShow((__bridgeCFTypeRef)(infoDic));

NSString*currentVersion=[infoDicobjectForKey:@"CFBundleShortVersionString"];

NSString*URL=@"https://itunes.apple.com/lookup?id=518966501";

//1.准备url地址

NSString*urlStr=URL;

NSURL*url=[NSURLURLWithString:urlStr];

//2.创建请求对象

NSMutableURLRequest*request=[NSMutableURLRequestrequestWithURL:url];

//2.1请求方式(默认方式为GET,可不写)

[requestsetHTTPMethod:@"GET"];

[NSURLConnectionsendAsynchronousRequest:requestqueue:[NSOperationQueuemainQueue]completionHandler:^(NSURLResponse*response,NSData*data,NSError*connectionError){

_actV.hidden=YES;

NSDictionary*dic=[NSJSONSerializationJSONObjectWithData:dataoptions:NSJSONReadingAllowFragmentserror:nil];

NSArray*infoArray=[dicobjectForKey:@"results"];

if([infoArraycount]){

NSDictionary*releaseInfo=[infoArrayobjectAtIndex:0];

NSString*lastVersion=[releaseInfoobjectForKey:@"version"];

//有新版本

if([lastVersioncompare:currentVersion]>0){

//根据主版本号判断是否需要强制更新

NSMutableString*cur1=[NSMutableStringstringWithString:currentVersion];

NSMutableString*cur2=[NSMutableStringstringWithString:currentVersion];

NSRangerange=NSMakeRange(1,4);

[cur1deleteCharactersInRange:range];

NSIntegercurFirst1=[cur1integerValue];

NSRangerange3=NSMakeRange(0,4);

[cur2deleteCharactersInRange:range3];

NSIntegercurLast=[cur2intValue];

NSMutableString*last1=[NSMutableStringstringWithString:lastVersion];

NSMutableString*last2=[NSMutableStringstringWithString:lastVersion];

[last1deleteCharactersInRange:range];

NSIntegerlastFirst1=[last1integerValue];

[last2deleteCharactersInRange:range3];

NSIntegerlastLast=[last2integerValue];

//主版本号更新大于1,强制更新

if(lastFirst1-curFirst1>=1||(curFirst1==lastFirst1&&curLast!=lastLast)){

UIAlertView*alert=[[UIAlertViewalloc]initWithTitle:@"版本更新"message:@"发现新版本,强烈建议您更新到最新版本,否则会影响您的正常使用"delegate:selfcancelButtonTitle:@"更新"otherButtonTitles:nil,nilnil];

alert.tag=100001;

[alertshow];

}

//祝版本号没有更新,不强制更新

else{

//trackViewURL=[releaseInfoobjectForKey:@"trackVireUrl"];

UIAlertView*alert=[[UIAlertViewalloc]initWithTitle:@"更新"message:@"有新的版本更新,是否前往更新?"delegate:selfcancelButtonTitle:@"关闭"otherButtonTitles:@"更新",nilnil];

alert.tag=100002;

[alertshow];

}

}

//没有新版本

else

{

UIAlertView*alert=[[UIAlertViewalloc]initWithTitle:@"更新"message:@"此版本为最新版本"delegate:selfcancelButtonTitle:@"确定"otherButtonTitles:nil,nilnil];

alert.tag=100003;

[alertshow];

}

}

}];

}

-(void)alertView:(UIAlertView*)alertViewclickedButtonAtIndex:(NSInteger)buttonIndex

{

//强制更新

if(alertView.tag==100001){

if(buttonIndex==0){

[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"https://itunes.apple.com/cn/app/id518966501"]];

}

}

//非强制更新

elseif(alertView.tag==100002){

if(buttonIndex==0){

}elseif(buttonIndex==1){

[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"https://itunes.apple.com/cn/app/lan-bi-tou/id935232659?mt=8"]];

}

}

//不需要更新

elseif(alertView.tag==100003){

}

}


如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网