[ios自动删除应用]分享iOS应用自动检查更新提示方法实例代码【推荐】

时间:2019-09-11  来源:ios  阅读:

以前我们检查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=&mt=8";
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
    }
}


请求http://itunes.apple.com/lookup?id=954270返回的数据给出的version为2.3, 与本地客户端版本号比较,即可判断有无更新。

通过此方法,我们可以在IOS应用当中提示是否有更新,这样可以让用户安装更新更安全的应用。

[ios自动删除应用]分享iOS应用自动检查更新提示方法实例代码【推荐】

http://m.bbyears.com/shoujikaifa/67534.html

推荐访问:
相关阅读 猜你喜欢
本类排行 本类最新