IOS 检查更新

作者: 小暖风 | 来源:发表于2017-08-19 14:21 被阅读16次

#pragma mark -检查更新

- (void)checkUpdateWithAPPID:(NSString*)APPID

{

//获取当前应用版本号

NSDictionary*appInfo = [[NSBundlemainBundle]infoDictionary];

NSString*currentVersion = [appInfoobjectForKey:@"CFBundleVersion"];

NSString*updateUrlString = [NSStringstringWithFormat:@"http://itunes.apple.com/lookup?id=%@",APPID];

NSURL*updateUrl = [NSURLURLWithString:updateUrlString];

versionRequest = [ASIFormDataRequestrequestWithURL:updateUrl];

[versionRequestsetRequestMethod:@"GET"];

[versionRequestsetTimeOutSeconds:60];

[versionRequestaddRequestHeader:@"Content-Type"value:@"application/json"];

//loading view

CustomAlertView*checkingAlertView = [[CustomAlertViewalloc]initWithFrame:NAVIGATION_FRAMEstyle:CustomAlertViewStyleDefaultnoticeText:@"正在检查更新..."];

checkingAlertView.userInteractionEnabled =YES;

[self.navigationController.viewaddSubview:checkingAlertView];

[checkingAlertViewrelease];

[versionRequestsetCompletionBlock:^{

[checkingAlertViewremoveFromSuperview];

NSError*error =nil;

NSDictionary*dict = [NSJSONSerializationJSONObjectWithData:[versionRequestresponseData]options:NSJSONReadingMutableContainerserror:&error];

if(!error) {

if(dict !=nil) {

//            DLog(@"dict %@",dict);

intresultCount = [[dictobjectForKey:@"resultCount"]integerValue];

if(resultCount == 1) {

NSArray*resultArray = [dictobjectForKey:@"results"];

//                DLog(@"version %@",[resultArray objectAtIndex:0]);

NSDictionary*resultDict = [resultArrayobjectAtIndex:0];

//                DLog(@"version is %@",[resultDict objectForKey:@"version"]);

NSString*newVersion = [resultDictobjectForKey:@"version"];

if([newVersiondoubleValue] > [currentVersiondoubleValue]) {

NSString*msg = [NSStringstringWithFormat:@"最新版本为%@,是否更新?",newVersion];

newVersionURlString = [[resultDictobjectForKey:@"trackViewUrl"]copy];

DLog(@"newVersionUrl is %@",newVersionURlString);

//                    if ([newVersionURlString hasPrefix:@"https"]) {

//                         [newVersionURlString replaceCharactersInRange:NSMakeRange(0, 5) withString:@"itms-apps"];

//                    }

UIAlertView*alertView = [[UIAlertViewalloc]initWithTitle:@"提示"message:msgdelegate:selfcancelButtonTitle:@"暂不"otherButtonTitles:@"立即更新",nilnil];

alertView.tag = 1000;

[alertViewshow];

[alertViewrelease];

}else

{

UIAlertView*alertView = [[UIAlertViewalloc]initWithTitle:@"提示"message:@"您使用的是最新版本!"delegate:selfcancelButtonTitle:nilotherButtonTitles:@"确定",nilnil];

alertView.tag = 1001;

[alertViewshow];

[alertViewrelease];

}

}

}

}else

{

DLog("error is %@",[errordebugDescription]);

}

}];

[versionRequestsetFailedBlock:^{

[checkingAlertViewremoveFromSuperview];

CustomAlertView*alertView = [[CustomAlertViewalloc]initWithFrame:NAVIGATION_FRAMEstyle:CustomAlertViewStyleWarningnoticeText:@"操作失败,请稍候再试!"];

[self.navigationController.viewaddSubview:alertView];

[alertViewrelease];

[alertViewselfRemoveFromSuperviewAfterSeconds:1.0];

}];

[versionRequeststartSynchronous];

}

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

{

DLog(@"newVersionUrl  is %@",newVersionURlString);

if(buttonIndex) {

if(alertView.tag == 1000) {

if(newVersionURlString)

{

[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:newVersionURlString]];

}

}

}

}

相关文章

  • iOS检查更新

    //以get的形式提交,get的参数就是上面的域名,parameters的参数是一个字典类型,将上面的字典作为它的...

  • iOS检查更新

    自从iOS8系统开始,用户可以在设置里面设置在WiFi环境下,自动更新安装的App。此功能大大方便了用户,但是一些...

  • iOS检查更新

  • IOS 检查更新

    #pragma mark -检查更新 -(void)checkUpdateWithAPPID:(NSString*...

  • iOS 检查更新

    1、从苹果服务器上查询已发布的最新应用版本号 请求的URL地址: 返回的数据为json格式(包括开发者ID,开发者...

  • iOS开发之获取App Store的上架信息(包括版本号)并实现

    由于iOS app不允许检查更新,凡是app在上架审核时出现“检查更新”字样的都有可能被打回,而检查更新功能是产品...

  • IOS检查应用更新

    使用这个方法,只传入你的appId即可,在只有需要更新时才做处理。 不依赖三方,不依赖后台 ps: 1.只要在it...

  • iOS 检查App版本更新

    可以通过 iTunes 接口检查 App 版本更新,接口为: 请求返回数很多,其中重要信息如下: 然后通过当前Ap...

  • iOS 版本检查更新(iVersion)

    iVersion的使用 在这里介绍一个版本检查更新三方库的使用,在github上已经1.9K星了,使用也是非常的简...

  • iOS APP检查版本更新

    iOS程序自动提示更新的实现方案大致分为两种:第一种,自己服务器提供一个接口,告知相关app的当前版本,是否需要更...

网友评论

    本文标题:IOS 检查更新

    本文链接:https://www.haomeiwen.com/subject/xkytdxtx.html