Summary:
We receive a new app update notification every day in the App Store, and when the app is opened, it's not the pop-up prompt, which automatically checks for updates, although it's annoying as a user to always see this hint, but as a developer it's best to keep users updated to the latest version. One way to reduce user boredom is to describe in detail the places and reasons for the update so that users can be more receptive to it. Now let's talk about how to automate check updates within the project.
Two ways:1. Check the version number given on the server and compare it to its version
If it is not a stand-alone application or game, it will often need to communicate with their own background server, as with other communications, you can open the app to the background to request the latest version number, get a reply, and its own version number of the comparison, if there is a new version, the user is prompted to update.
This method is more common in Android applications, because the application market is more and more miscellaneous, from their own to master the update will be much more comfortable, but as the iOS side, because the submission of the new version to the App Store for a period of time for the review to allow users to download, so real-time poor, This is also why sometimes encounter the application prompt update and the App store does not see the reason for updating the word, the solution is to wait for the audit through the background server to provide the version number update, it is also very convenient, another disadvantage may be the need for a server.
This method and other communication with the background is no different, it is not specifically said.
2. Request version information from the App Store and compare it to its own version
The unity of the Apple market here is the advantages, all the applications are here, as long as the update submitted to the audit through the latest version information can be obtained, not through the words obtained is still the original version information, real-time is very good, and in the request version information, go to the app Store download links will also be returned, can be used directly, very convenient. But like Apple's server request data to imagine or not to their own server to request the reliable, specific use of how the effect, and so I experience, I will know.
This approach requires data to be requested from Apple's servers, which is highlighted in this article.
to request version information from the App Store:
AppID: When we create an app in our own developer center, we get a dedicated AppID for the app, which is not the identifier we created when we created the certificate, but a unique set of numbers that are automatically generated, after the app is created in the Dev Center, after the app's Web page , the number at the back of the URL is the AppID of our application, and we are using this AppID to tell the App Store what version of the app we're querying.
Find their own appid after the request for version information, the URL is fixed, change only the last AppID, at the same time we also get the current version, here simply write a, really application, it should be long-term preservation in the local.
NSString *currentversion = @ "0.9"; Now version NSString *appid = @ "Your app's AppID";//the app's ID //Request URL nsstring *versionurl = [NSString stringwithformat:@ "http://itunes.apple.com/cn/lookup?id=%@", AppID]; Nsurlrequest *urlrequest = [[Nsurlrequest alloc] Initwithurl:[nsurl Urlwithstring:versionurl]];
to process the returned data:
The data returned by the App Store is a multi-layered, nested JSON data that gives you a direct explanation of how to get the version number and download link we need. Actually get the other information, specifically want to know the words can be exported to see.
Replies received NSData *response = [nsurlconnection sendsynchronousrequest:urlrequest returningresponse:nil Error:nil]; Convert to a key-value pair form nserror *error; Nsdictionary *appinfodic = [nsjsonserialization jsonobjectwithdata:response options:nsjsonreadingmutableleaves Error :&error]; if (error) { NSLog (@ "error:%@", [error description]); return; } NSLog (@ "%@", appinfodic);//Output view the details of the reply //To see if the content is empty nsarray *resultsarray = [Appinfodic objectforkey : @ "Results"]; if (![ Resultsarray Count]) { NSLog (@ "Error:resultsarray = = nil"); return; } Get information on specific needs nsdictionary *infodic = [Resultsarray objectatindex:0]; Self.latestversion = [Infodic objectforkey:@ "version"];//release number Self.trackviewurl = [Infodic objectforkey:@] Trackviewurl "];//Updated URL address
Here, after the first conversion to dictionary format, you can output to see what information is obtained, and then we will specify the version number we need to compare, and go to the App Store to update the URL address.
Prompt user for update:
Once you get to the latest version number on the App store, you can compare it to the locally stored version number, and if you have a new version, a pop-up prompt prompts the user for a new version.
Pop-up Cue box if (![ CurrentVersion IsEqualToString:self.latestVersion]) { NSString *messagestr = [NSString stringwithformat:@] new version found: %@, do you want to go to the update? ", self.latestversion]; Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "Update Prompt" Message:messagestr delegate:self cancelbuttontitle:@ " Cancel "otherbuttontitles:@" Update ", nil"; Alert.tag = 10000;//the Prompt box with the label notification is the updated prompt box [alert show];
PS: When the application changes a lot of versions, we may be difficult to maintain support all the version, sometimes the old version of the robustness is not very good, and even the use of a lot of problems, it may be necessary to force the update, this is the prompt box should only provide updated button, do not update will not allow the use of the app. If the first method is used to detect the update, we can pass a data to tell the app how many versions of the update are needed, but if the second method is used,How do I tell the app to update if it detects updates to the App Store? Here I have not thought well, hoped that has the great God to be able to teach a bit ~
If the user clicks on the update, go to the App Store via the URL you just acquired to update:
Response of the Prompt box-(void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (Nsinteger) Buttonindex { if ( Alertview.tag = = 10000) {//Is the updated prompt box if (buttonindex = = 1) { //Go to App Store update nsurl *url = [Nsurl urlwithstring : Self.trackviewurl]; [[UIApplication Sharedapplication]openurl:url];}}
This completes the implementation of the second method, requesting a version number from the App Store for automatic detection of updates.
Here are engineering Source: https://github.com/Cloudox/UpdateTest
Reprint please indicate the source, thank you
Resources:
How iOS development app implements detection updates: http://jingyan.baidu.com/article/335530da8b1e0419cb41c305.html
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
iOS automatically check for updates