Ios development-APP upgrade implementation
Directly run the Code:
/*** Check software upgrade required */-(void) checkVersion {NSURL * url = [NSURL URLWithString: [NSString stringWithFormat: @ http://itunes.apple.com/cn/lookup? Id = % I, iFeverAPPID]; ASIHTTPRequest * request = [[ASIHTTPRequest alloc] initWithURL: url]; [request setUseCookiePersistence: YES]; [request setDelegate: self]; [request setDidFailSelector: @ selector (Response :)]; [request setDidFinishSelector: @ selector (getVersionRequestSuccess :)]; [request startAsynchronous]; // start asynchronous request}-(void) getVersionRequestFailed :( ASIHTTPRequest *) request1 {NSLog (@ from AppSto Re failed to get version information !!);} -(Void) initialize :( ASIHTTPRequest *) request1 {NSString * newVersion; NSData * responseData = [request1 responseData]; NSDictionary * dic = [NSJSONSerialization JSONObjectWithData: responseData options: response error: nil]; NSArray * resultArray = [dic objectForKey: @ results]; for (id config in resultArray) {newVersion = [config valueForKey: @ version];} if (newVersion) {N SLog (@ the version obtained through AppStore is: % @, newVersion);} // obtain the local version NSString * localVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey: @ CFBundleVersion]; NSString * msg = [NSString stringWithFormat: @ your current version is V % @. Check whether to download the new version V % ?, LocalVersion, newVersion]; if ([newVersion floatValue]> [localVersion floatValue]) {UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ upgrade prompt! Message: msg delegate: self cancelButtonTitle: @ otherButtonTitles: @ upgrade now, nil]; alert. tag = kVersionNeedUpdateAlertTag; [alert show];}
-(Void) alertView :( UIAlertView *) alertView clickedButtonAtIndex :( NSInteger) buttonIndex {if (alertView. tag = kVersionNeedUpdateAlertTag) {// Software Update reminder if (buttonIndex = 1) {NSURL * url = [NSURL URLWithString: [NSString stringWithFormat: @ https://itunes.apple.com/cn/app/wan-zhuan-quan-cheng/id% I? Mt = 8, iFeverAPPID]; [[UIApplication sharedApplication] openURL: url];/* // method 2 to enable iTunes: This method always prompts "unable to connect to itunes ", NSString * iTunesLink = @ itms-apps: // phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftwareUpdate? Id = % I & mt = 8; NSURL * url = [NSURL URLWithString: [NSString stringWithFormat: @ itms-apps: // phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftwareUpdate? Id = % I & mt = 8, iFeverAPPID]; [[UIApplication sharedApplication] openURL: url]; */}
If you want to know the information returned when the network requests an AppStore, you can open this link: http://itunes.apple.com/cn/lookup? Id = 465039730