Today to do the version of the automatic update, I think actually did not do this function necessary but after all, the boss is the eldest, then knocked on it is to see a big capitalization forget who is sorry ha
Nserror *error;
NSString *appid = @ "AppID";
NSString *urlstr = [NSString stringwithformat:@ "http://itunes.apple.com/lookup?id=%@", AppID];
Nsurl *url = [Nsurl urlwithstring:urlstr];
Nsurlrequest *request = [Nsurlrequest Requestwithurl:url];
NSData *response = [nsurlconnection sendsynchronousrequest:request returningresponse:nil Error:nil];
Nsdictionary *appindodic = [nsjsonserialization jsonobjectwithdata:response options:nsjsonreadingmutableleaves Error :&error];
if (Error) {
NSLog (@ "error---->%@", [error description]);
Return
}
Nsarray *resultsarray = [appindodic objectforkey:@ "Results"];
if (![ Resultsarray Count]) {
NSLog (@ "Error--->resul = = nil");
Return
}
Information about the store
Nsdictionary *infidic = [Resultsarray objectatindex:0];
NSLog (@ "%@", infidic);
The version number on the shelf
NSString *latestversion = [infidic objectforkey:@ "version"];
Url
_trackviewurl = [Infidic objectforkey:@ "Trackviewurl"];
Name
NSString *trackname = [infidic objectforkey:@ "TrackName"];
Nsdictionary *infodict = [[NSBundle mainbundle] infodictionary];
Current version number
NSString *currentversion = [infodict objectforkey:@ "cfbundleversion"];
NSLog (@ "%@---------------%@", currentversion,latestversion);
Double doublelatestversion = [Latestversion doublevalue];
Double doublecurrentversion = [CurrentVersion Doublevalue];
if (Doublecurrentversion < doublelatestversion) {
NSString *titleste = [NSString stringwithformat:@ "Check for updates:%@", TrackName];
NSString *messagestr = [NSString stringwithformat:@ "Discover new version (%@), whether Upgrade", latestversion];
Uialertview *alert = [[Uialertview alloc]initwithtitle:titleste message:messagestr delegate:self cancelButtonTitle:@ ' Cancel "otherbuttontitles:@" Upgrade ", nil";
Alert.delegate = self;
[Alert show];
}
-(void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (Nsinteger) Buttonindex
{
if (Buttonindex = = 1) {
Skip to Apple Store
[[UIApplication sharedapplication] Openurl:[nsurl Urlwithstring:_trackviewurl]];
}
IOS Automatic Updates