1. Get the version of the current run program
If we need to implement the version of the app update automatically, we need to get the version information of the current running program and the latest version information released in the App Store.
The version information of the currently running program can be obtained in Mainbundle:
Nsdictionary *infodict = [[NSBundle mainbundle] infodictionary];
NSString *currentversion = [infodict objectforkey:@ "cfbundleversion"];
2. Get the latest version released above the App Store
The latest version of the information available in the App Store is a little more complicated, with two options and the same idea:
One: Store the latest release information on a server, and query the server when needed;
Queries to the server simply send the requested version information to the server and the server returns.
Second: When necessary, to the App Store query;
We can send a request to the App store to query the application information, including the author, version, app introduction page address, and other information.
The specific steps are as follows:
1. Send Request:
A. Search by App Name:
Http://itunes.apple.com/search?term= your application name &entity=software
B. A more precise approach is to look up the ID of the app:
Http://itunes.apple.com/lookup?id= the ID of your application
If it's a Chinese area program, use this: http://itunes.apple.com/cn/lookup?id=
This ID is an application ID on the App Store and is typically a string of numbers such as: 301724683
2, parse the return data. The original data obtained after parsing is the following:
{
Resultcount = 1;
Results = (
{
ArtistID = 301724683;
Artistname = Citibank;
Artistviewurl = "http://itunes.apple.com/us/artist/citibank/id301724683?uo=4";
artworkUrl100 = "Http://a5.mzstatic.com/us/r1000/117/Purple/a1/85/a9/mzl.hvwnfdkw.png";
artworkUrl512 = "Http://a5.mzstatic.com/us/r1000/117/Purple/a1/85/a9/mzl.hvwnfdkw.png";
ARTWORKURL60 = "Http://a2.mzstatic.com/us/r1000/099/Purple/67/86/7e/mzi.utfdvrgy.png";
averageuserrating = "3.5";
Averageuserratingforcurrentversion = 5;
contentadvisoryrating = "4+";
currency = USD;
Description = "Description of you app.";
Features = (
Iosuniversal
);
Filesizebytes = 4141195;
Genreids = (
6015
);
Genres = (
Finance
);
Ipadscreenshoturls = (
"Http://a1.mzstatic.com/us/r1000/095/Purple/e0/a6/17/mzl.pbbxcjzt.1024x1024-65.jpg",
"Http://a3.mzstatic.com/us/r1000/036/Purple/cc/14/98/mzl.dyairego.1024x1024-65.jpg"
);
isgamecenterenabled = 0;
kind = software;
LANGUAGECODESISO2A = (
En
);
Price = 0;
Primarygenreid = 6015;
Primarygenrename = Finance;
ReleaseDate = "2011-01-24t06:14:35z";
Releasenotes = "* View Real-time streaming prices for U.S. Treasuries \n\n* Open and Save your Citi Ite PDF Reader and Library such as ibooks\n\n* Search for your favorite videos ";
Screenshoturls = (
"Http://a3.mzstatic.com/us/r1000/066/Purple/17/51/fb/mzl.zywiavgn.png",
"Http://a5.mzstatic.com/us/r1000/026/Purple/73/85/97/mzl.csmdtndk.png"
);
Sellername = "Citibank, N.a."
Sellerurl = "http://";
Supporteddevices = (
All
);
Trackcensoredname = "Citi Velocity";
trackcontentrating = "4+";
TrackID = 414697122;
TrackName = "Citi Velocity";
Trackviewurl = "http://itunes.apple.com/us/app/citi-velocity/id414697122?mt=8&uo=4";
Userratingcount = 5;
Userratingcountforcurrentversion = 1;
Version = "1.4";
Wrappertype = software;
}
);
}
You can then get the results array, as shown in the specific code below:
Nsdictionary *jsondata = [Datapayload jsonvalue];
Nsarray *infoarray = [Jsondata objectforkey:@ "Results"];
Nsdictionary *releaseinfo = [Infoarray objectatindex:0];
NSString *latestversion = [releaseinfo objectforkey:@ "version"];
Latestversion is the latest release on the App Store