-(void)getstAte{
NSError*error;
NSString*lastsVersion;
NSString*trackViewUrl;
NSString*trackName;
NSString*currentVersion;
NSString*appid =@"1050032423";
NSString*urlStr = [NSStringstringWithFormat:@"http://itunes.apple.com/lookup?id=%@",@"1050032423"];
NSURL*url = [NSURLURLWithString:urlStr];
NSURLRequest*request = [NSURLRequestrequestWithURL:url];
NSData*response = [NSURLConnectionsendSynchronousRequest:requestreturningResponse:nilerror:nil];
NSDictionary*appInfoDic = [NSJSONSerializationJSONObjectWithData:responseoptions:NSJSONReadingMutableLeaveserror:&error];
if(error) {
NSLog(@"error:%@",[errordescription]);
//return;
}
NSArray*resultsArray = [appInfoDicobjectForKey:@"results"];
if(![resultsArraycount]) {
NSLog(@"error: resultsArray == nil");
//return;
}
NSDictionary*infoDic = [resultsArrayobjectAtIndex:0];
lastsVersion = [infoDicobjectForKey:@"version"];
trackViewUrl = [infoDicobjectForKey:@"trackViewUrl"];
trackName = [infoDicobjectForKey:@"trackName"];
//获取当前版本
NSDictionary*infoDict = [[NSBundlemainBundle]infoDictionary];
currentVersion = [infoDictobjectForKey:@"CFBundleShortVersionString"];
doubledoubleCurrentVersion = [currentVersiondoubleValue];
doubledoubleUpdateVersion = [lastsVersiondoubleValue];
NSLog(@"当前版本是:%@",currentVersion);
NSLog(@"商店版本是:%@",lastsVersion);
if(doubleCurrentVersion < doubleUpdateVersion) {
NSString*titleStr = [NSStringstringWithFormat:@"检查更新:%@",trackName];
NSString*messageStr = [NSStringstringWithFormat:@"发现新版本(%@),是否升级?",lastsVersion];
UIAlertView*alert = [[UIAlertViewalloc]initWithTitle:titleStr
message:messageStr
delegate:self
cancelButtonTitle:@"退出"
otherButtonTitles:@"升级",nil];
alert.tag= [appidintValue];
[alertshow];
}
}
- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
//退出
if(buttonIndex==0) {
[selfexitApplication];
}else{
//更新
//https://itunes.apple.com/cn/app/jiao-shi-pei-xun-wang/id1050032423?mt=8
[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"itms-apps://itunes.apple.com/cn/app/jiao-shi-pei-xun-wang/id1050032423?mt=8"]];
[selfexitApplication];
}
}