iOS Development App version update, reminding

Source: Internet
Author: User
/**
* Detecting the parameters to be used for version upgrade
* * Ifeverappid = @ "1076057848"; AppId; Invoke method to detect version update [selfcheckversion];
*
* Detect whether the software needs to be upgraded
*/
-(void) checkversion
{
Get the current application version number
Nsdictionary *appinfo = [[Nsbundlemainbundle] infodictionary];
NSString *currentversion = [appinfoobjectforkey:@ "Cfbundleversion"];
Use __block to change the value of a variable in a local scope
__block nsstring *newversion = @ "";
NSString *updateurlstring = [nsstringstringwithformat:@ "Http://itunes.apple.com/lookup?id=%ld", (long) [ Ifeverappidintegervalue]];

NSString * str = [updateurlstringstringbyaddingpercentescapesusingencoding:nsutf8stringencoding];
Afhttprequestoperationmanager *manager = [Afhttprequestoperationmanagermanager];
[Manager get:str Parameters:nil success:^ (afhttprequestoperation*operation, id responseobject) {
NSLog (@ "123 +%@", operation);
Nsdictionary *resultdic = Responseobject;
Nsarray *resultarray = [resultdicobjectforkey:@ "Results"];

For (Idconfig in resultarray) {
newversion = [Config valueforkey:@ "version"];
}
if (newversion) {
NSLog (@ "obtained through the App Store version number is:%@", newversion);
}

result = = 1

Nscomparisonresult result = [NewVersion compare:currentversion];
if (result = = 1) {//appstore version is greater than the current version
NSString *versionmessagestr = [NSString stringWithFormat: @ "Current version%@, the latest version is%@, please upgrade.", Currentversion,newversion];
Uialertview *alert = [[Uialertview alloc] Initwithtitle: @ "upgrade prompt!" Message:versionmessagestr delegate:self CancelB Uttontitle: @ "Next time" Otherbuttontitles: @ "Upgrade Now", Nil];
Alert. tag = Kversionneedupdatealerttag;
[Alert show];
}

} Failure: ^ ( Afhttprequestoperation *operation, Nserror *error) {
NSLog (@ "234 +%@", error);
}];
}


#pragma mark-uialertdelegate method
When the program is running in front of the push, give an alert, the user chooses to view, executes this method, and jumps to the specified page
-(void) Alertview: ( Uialertview *) Alertview Clickedbuttonatindex: ( Nsinteger) Buttonindex
{
if (Buttonindex = = 1) {
Software needs to update reminders
if (alertview. Tag = = Kversionneedupdatealerttag) {
Nsurl *url = [Nsurl urlwithstring: [NSString stringWithFormat: @] Https://itunes.apple.com/cn/app/wan-zhuan-quan-cheng             /id%@?mt=8 ", Ifeverappid]];                     [[Uiapplicationsharedapplication]openurl:url]; }
} }

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.