iOS detects version updates via itunes search and prompts users to update!

Source: Internet
Author: User

Original address: iOS via itunes Search detects version updates, and prompts the user to update.

If we want to detect updates to the app version, we have to get information about the version of the currently running app version and the latest version released on the App Store.


The current run version information can be obtained from the bundle version in the Info.plist file:

[CPP] view plain copy print?       Nsdictionary *infodic = [[NSBundle mainbundle] infodictionary];              Cfshow (Infodic); NSString *appversion = [infodic objectforkey:@ "cfbundleversion"];

This will get you to the version of the currently running app.


There are two ways to get the latest version of the current App Store

On a particular server, publish and store the latest version information of the app, and request queries from the server when needed.


Second, from the App Store query, you can get to the app's author, connection, version, and so on. Official Related documents

Www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.htm


The specific steps are as follows:
1, send the request in POST mode:
Http://itunes.apple.com/search?term= your application name &entity=software

A more precise approach is to look for the app's ID to find:
Http://itunes.apple.com/lookup?id= the ID of your application

#define APP_URL http://itunes.apple.com/lookup?id= The ID of your application

The ID of your application is the Apple ID in the itunes Connect

2, to parse the required data from the response data obtained. Because the information from the App Store query is in JSON format, it needs to be parsed. The original data obtained after parsing is the following:
{
Resultcount = 1;
Results = (
{
ArtistID = Developer ID;
artistname = developer Name;
Price = 0;
isgamecenterenabled = 0;
kind = software;
LANGUAGECODESISO2A = (
En
);
Trackcensoredname = review name;
Trackcontentrating = rating;
TrackID = Application ID;
TrackName = Application Name ";
Trackviewurl = Application Introduction URL;
Userratingcount = user Rating;
Userratingcountforcurrentversion = 1;
Version = edition number;
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"];
NSString *trackviewurl = [Releaseinfo objectforkey:@ "Trackviewurl"];

If you copy Trackviewurl's actual address and open it in a browser, you will open the introduction page for your application in the App Store. Of course we can also call safari in the code to open it.
UIApplication *application = [UIApplication sharedapplication];
[Application Openurl:[nsurl Urlwithstring:trackviewurl]];


[CPP]  View plain copy print? -(void) Oncheckversion: (nsstring *) currentversion   {       nsstring  *URL = APP_URL;       nsmutableurlrequest *request =  [[NSMutableURLRequest alloc] init];       [request seturl:[ nsurl urlwithstring:url]];       [request sethttpmethod:@ "POST"];        NSHTTPURLResponse *urlResponse = nil;        NSError *error = nil;       nsdata *recerveddata  = [nsurlconnection sendsynchronousrequest:request returningresponse:&urlresponse  error:&error];              NSString  *results = [[nsstring alloc] initwithbytes:[recerveddata bytes] length:[recerveddata length] encoding:nsutf8stringencoding];        nsdictionary *dic = [results jsonvalue];       nsarray * infoarray = [dic objectforkey:@ "Results"];       if  ([ Infoarray count])  {           nsdictionary * releaseinfo = [infoarray objectatindex:0];            nsstring *lastversion = [releaseinfo objectforkey:@ "Version"];                      if   (![ Lastversion isequaltostring:currentversion])  {                trackviewurl = [releaseinfo objectforkey:@ "TrackViewURL"];     &Nbsp;          uialertview *alert = [[[ uialertview alloc] initwithtitle:@ "Update"  message:@ has a new version update and whether to go to the update. " delegate:self cancelbuttontitle:@" closes " otherbuttontitles:@ Update", nil] autorelease];                [alert show];            }       }  }  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.