If we need to automatically update the version of the app, we need to obtain the version information of the current running program and the latest version released in the appstore.
The version information of the currently running program, which can be obtained in mainbundle:
[CPP]
View plaincopyprint?
- Nsdictionary * infodict = [[nsbundle mainbundle] infodictionary];
- Nsstring * CurrentVersion = [infodict objectforkey: @ "cfbundleversion"];
The retrieval of the latest version released in the appstore is a little complicated. There are two solutions with the same idea:
1. Store the latest version information on a server and query the server whenever necessary;
Second: query the appstore as needed;
Here I will introduce the second method: query application information from the appstore, including the author, version, and page address of the app.
For good English, refer to the Apple documentation: www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html
The procedure is as follows:
1. Send the request in post mode:
Http://itunes.apple.com/search? Term = your application name & entity = Software
The more accurate method is to search by app id:
Http://itunes.apple.com/lookup? Id = the ID of your application
2. parse the required data from the obtained response data. Because the information obtained from the appstore query is in JSON format, it must be parsed. The raw data obtained after parsing is as follows:
[HTML]
View plaincopyprint?
- {
- Resultcount = 1;
- Results = (
- {
- Artistid = 301724683;
- Artistname = Citigroup;
- 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 * Open and save your Citi research in your favorite pdf reader and Library such as ibooks \ 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. .";
- 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;
- }
- );
- }
Then obtain the results array. The Code is as follows:
[CPP]
View plaincopyprint?
- Nsdictionary * jsondata = [datapayload jsonvalue];
- Nsarray * infoarray = [jsondata objectforkey: @ "Results"];
- Nsdictionary * releaseinfo = [infoarray objectatindex: 0];
- Nsstring * latestversion = [releaseinfo objectforkey: @ "version"];
- Nsstring * trackviewurl = [releaseinfo objectforkey: @ "trackviewurl"];
If you copy the actual address of trackviewurl and open it in the browser, the introduction page of your application in appstore will be displayed. Of course, we can also call safari in the code to open it.
[CPP]
View plaincopyprint?
- Uiapplication * Application = [uiapplication sharedapplication];
- [Application Openurl: [nsurl urlwithstring: trackviewurl];
Reprinted: http://blog.csdn.net/kesalin/article/details/6605934