最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
分享iOS应用自动检查更新提示方法实例代码【推荐】
时间:2015-01-17 编辑:简简单单 来源:一聚教程网
以前我们检查iOS应用版本,做法是在自己的服务器上记录最新版本号,ios客户端请求后再与本地对比,如果服务器上的版本高就提示更新,这个做法比较简单不过需要单独的服务器支持。现在我们的做法与上述类似,不过不需要服务器支持,以下是该方法的源代码。
代码如下 | 复制代码 |
NSString *version = @""; NSURL *url = [NSURL URLWithString:@"http://itunes.apple.com/lookup?id=954270"]; versionRequest = [ASIFormDataRequest requestWithURL:url]; [versionRequest setRequestMethod:@"GET"]; [versionRequest setDelegate:self]; [versionRequest setTimeOutSeconds:150]; [versionRequest addRequestHeader:@"Content-Type" value:@"application/json"]; [versionRequest startSynchronous]; //Response string of our REST call NSString* jsonResponseString = [versionRequest responseString]; NSDictionary *loginAuthenticationResponse = [jsonResponseString objectFromJSONString]; NSArray *configData = [loginAuthenticationResponse valueForKey:@"results"]; for (id config in configData) { version = [config valueForKey:@"version"]; } //Check your version with the version in app store if (![version isEqualToString:[itsUserDefaults objectForKey:@"version"]]) { ProAlertView *createUserResponseAlert = [[ProAlertView alloc] initWithTitle:@"New Version!!" message: @"A new version of app is available to download" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: @"Download", nil]; [createUserResponseAlert show]; [createUserResponseAlert release]; } - (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { // the user clicked one of the OK/Cancel buttons if (buttonIndex == 1) { NSString *iTunesLink = @"itms-apps://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftwareUpdate?id= [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]]; } } |
请求http://itunes.apple.com/lookup?id=954270返回的数据给出的version为2.3, 与本地客户端版本号比较,即可判断有无更新。
通过此方法,我们可以在IOS应用当中提示是否有更新,这样可以让用户安装更新更安全的应用。
相关文章
- 实现安卓app自动更新功能实例方案 03-06
- sora软件价格介绍 02-22
- sora官网入口地址一览 02-22
- Sora生成的视频使用教程 02-22
- 《梦幻西游》元宵灯谜线索答案大全2024 02-22
- 《原神》有朋自远方来第一天通关攻略 02-22