Update reminder and score reminder for iphone/ipad apps

Source: Internet
Author: User

When you use an iphone/ipad app, sometimes the app has an update and upgrade. The appstore will remind you of the corresponding updates. In the app, you need to remind the user of the updates when opening the app, in this case, you need to write a reminder in the program. The resume pop-up box reminds the user of this issue and it will be OK!

The specific code is shared with you. Please note that you must have the app id. So what do you do if the app has no id for the first time? When the review is launched, you will get the id, and then you can enter the id directly.


First, write a singleton class:

 

/// AppUpdateGrade. h // QingDaoBroadcastIpad // Created by iHope on 13-7-23. // Copyright (c) 2013 hlren. all rights reserved. // Ren haili # import <Foundation/Foundation. h> @ interface AppUpdateGrade: NSObject {NSString * appId; // app id NSString * trackViewUrl; // app address} + (AppUpdateGrade *) sharedAppupdateGrade; // create-(void) appUpdate :( NSString *) appleID; // Update-(void) appGrade :( NSString *) appleID; // rating @ end
/// AppUpdateGrade. m // QingDaoBroadcastIpad /// Created by iHope on 13-7-23. // Copyright (c) 2013 hlren. all rights reserved. // # import "AppUpdateGrade. h "@ implementation AppUpdateGradestatic AppUpdateGrade * appUpdateGrade = nil; + (AppUpdateGrade *) sharedAppupdateGrade {@ synchronized (self) {if (appUpdateGrade = nil) {appUpdateGrade = [[self alloc] init] ;}return appUpdateGrade ;}// update and upgrade-(void) app Update :( NSString *) appleID {appId = appleID; // http://itunes.apple.com/lookup? Id = xx // obtain json data from the Apple Server Based on appid, and then obtain the version information NSMutableURLRequest * request = [[NSMutableURLRequest alloc] init] From the json data; // set URL [request setURL: [NSURL URLWithString: [NSString stringWithFormat: @ "http://itunes.apple.com/lookup? Id = % @ ", appleID]; // set the HTTP method [request setHTTPMethod: @" GET "]; // request for sending synchronization, in this case, the returnData is the returned data records NSData * returnData = [NSURLConnection sendSynchronousRequest: request failed: nil error: nil]; NSDictionary * jsonData = [NSJSONSerialization failed: returnData options: 0 error: nil]; NSLog (@ "% @", jsonData); NSArray * infoArray = [jsonData objectForKey: @ "results"]; if (infoArray. count! = 0) {NSDictionary * releaseInfo = [infoArray objectAtIndex: 0]; NSString * latestVersion = [releaseInfo objectForKey: @ "version"]; NSString * trackViewUrl1 = [releaseInfo objectForKey: @ "trackViewUrl"]; // address: trackViewUrl = trackViewUrl1; // address: double doubleUpdateVersion = [latestVersion doubleValue]; // obtain the current version information // The version information of the currently running program, which can be obtained in mainBundle: NSDictionary * infoDict = [NSBundle mainB Undle] infoDictionary]; NSString * currentVersion = [infoDict objectForKey: @ "CFBundleVersion"]; double doubleCurrentVersion = [currentVersion doubleValue]; NSLog (@ "doubleCurrentVersion: % f, % f ", doubleCurrentVersion, doubleUpdateVersion); if (doubleCurrentVersion <doubleUpdateVersion) {UIAlertView * alert; alert = [[UIAlertView alloc] initWithTitle: @ "app name" message: @ "there are new versions, upgrade! "Delegate: self cancelButtonTitle: @" cancel "otherButtonTitles: @" Upgrade ", nil]; alert. tag = 1001; [alert show] ;}} else {// none of the app }}// rating-(void) appGrade :( NSString *) appleID {appId = appleID; BOOL neverGrade = [[[NSUserDefaults standardUserDefaults] objectForKey: @ "neverGrade"] boolValue]; if (neverGrade! = YES) {// reminder rating: UIAlertView * alert; alert = [[UIAlertView alloc] initWithTitle: @ "app name" message: @ "go to appstore to score" delegate: self cancelButtonTitle: @ "cancel" otherButtonTitles: @ "Go now", @ "no longer remind", nil]; alert. tag = 1000; [alert show] ;}}- (void) alertView :( UIAlertView *) alertView clickedButtonAtIndex :( NSInteger) buttonIndex {switch (alertView. tag) {case 1000: {// rating // Never Review Button if (buttonIndex = 2) {NSString * number = [NSString stringWithFormat: @ "% d", YES]; [[NSUserDefaults standardUserDefaults] setObject: number forKey: @ "neverGrade"]; [[NSUserDefaults standardUserDefaults] synchronize];} // Review Button else if (buttonIndex = 1) {NSString * number = [NSString stringWithFormat: @ "% d", YES]; [[NSUserDefaults standardUserDefaults] setObject: number forKey: @ "neverGrade"]; [[NSUserDefault S standardUserDefaults] synchronize]; // "itms-apps: // ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews? Type = Purple + Software & id = NSString * str = [NSString stringWithFormat: @ "itms-apps: // ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews? Type = Purple + Software & id = % @ ", appId]; [[UIApplication sharedApplication] openURL: [NSURL URLWithString: str] ;}} break; case 1001: {// upgrade if (buttonIndex = 1) {NSLog (@ "% @", trackViewUrl); [[UIApplication sharedApplication] openURL: [NSURL URLWithString: trackViewUrl];} break; default: break; }}@ end


1. update and upgrade

You need to get the version of the current application and the version of the previous version. In comparison, do you need to update the version!

Current application version:

NSDictionary * infoDict = [[NSBundle mainBundle] infoDictionary];
NSString * currentVersion = [infoDict objectForKey: @ "CFBundleVersion"];

Previous application version:

Need to request http://itunes.apple.com/lookup? Id = appid to obtain data and analyze the version;

2. Application rating

"Itms-apps: // ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews? Type = Purple + Software & id = appid"

You can directly open this link to grade the application;

 
 


Use, import # import "AppUpdateGrade. h"

 

Upgrade [[AppUpdateGrade sharedAppupdateGrade] appUpdate: @ "appid"]; // score afterDelay seconds 60*1 = 60 Minutes, indicating that the pinfen method is called one minute later [self defined mselector: @ selector (pinfen) withObject: self afterDelay: 1]; // upgrade [[AppUpdateGrade sharedAppupdateGrade] appUpdate: @ "appid"]; // score afterDelay seconds 60*1 = 60 Minutes, indicating that the pinfen method is called one minute later [self defined mselector: @ selector (pinfen) withObject: self afterDelay: 1];


 

(Void) pinfen {// score [[AppUpdateGrade sharedAppupdateGrade] appGrade: @ "appid"] ;}- (void) pinfen {// score [[AppUpdateGrade sharedAppupdateGrade] appGrade: @ "appid"];}

 

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.