iphone/ipad应用的升级更新提醒和评分提醒

在使用iphone/ipad应用的时候,有时候应用有更新升级,appstore会提醒用户有相应的更新,程序中需要在用户打开应用的时候提醒用户更新,那么就需要自己在程序当中写一个提醒事项,简历弹出框提醒用户一下,就ok了!

具体代码分享给大家,请大家注意,必须要有app的id。那么你会想应用第一次没有id怎么办?审请上线的时候就会得到id了,到时候有了id直接填上去就行了。

首先写一个单例类:

[cpp]  view plain copy
  1. //  
  2. //  AppUpdateGrade.h  
  3. //  QingDaoBroadcastIpad  
  4. //  
  5. //  Created by iHope on 13-7-23.  
  6. //  Copyright (c) 2013年 hlren. All rights reserved.  
  7. //  任海丽  
  8.   
  9. #import <Foundation/Foundation.h>  
  10.   
  11. @interface AppUpdateGrade : NSObject  
  12. {  
  13.     NSString *appId; //app的id  
  14.     NSString *trackViewUrl; //app的地址  
  15. }  
  16. +(AppUpdateGrade*)sharedAppupdateGrade; //创建  
  17. -(void)appUpdate:(NSString *)appleID; //更新  
  18. -(void)appGrade:(NSString *)appleID; //评分  
  19.   
  20. @end  

实现类:

[cpp]  view plain copy
  1. //  
  2. //  AppUpdateGrade.m  
  3. //  QingDaoBroadcastIpad  
  4. //  
  5. //  Created by iHope on 13-7-23.  
  6. //  Copyright (c) 2013年 hlren. All rights reserved.  
  7. //  
  8.   
  9. #import "AppUpdateGrade.h"  
  10.   
  11. @implementation AppUpdateGrade  
  12.   
  13. static AppUpdateGrade* appUpdateGrade = nil;  
  14. +(AppUpdateGrade*)sharedAppupdateGrade  
  15. {  
  16.     @synchronized(self)  
  17.     {  
  18.         if (appUpdateGrade == nil)  
  19.         {  
  20.             appUpdateGrade = [[self alloc] init];  
  21.         }  
  22.     }  
  23.     return appUpdateGrade;  
  24. }  
  25.   
  26. //更新升级  
  27. -(void)appUpdate:(NSString *)appleID  
  28. {  
  29.     appId = appleID;  
  30.     //http://itunes.apple.com/lookup?id=xx  
  31.       
  32.     //根据appid从苹果服务器上得到json数据,再从json数据中得到版本信息   
  33.     NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];  
  34.     // 设置URL  
  35.     [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",appleID]]];  
  36.     // 设置HTTP方法  
  37.     [request setHTTPMethod:@"GET"];  
  38.     // 发送同步請求, 這裡得returnData就是返回得數據楽  
  39.     NSData *returnData = [NSURLConnection sendSynchronousRequest:request    returningResponse:nil error:nil];  
  40.       
  41.     NSDictionary *jsonData = [NSJSONSerialization JSONObjectWithData:returnData options:0 error:nil];  
  42.     NSLog(@"%@",jsonData);  
  43.       
  44.     NSArray *infoArray = [jsonData objectForKey:@"results"];  
  45.     if (infoArray.count!=0) {  
  46.         NSDictionary *releaseInfo = [infoArray objectAtIndex:0];  
  47.         NSString *latestVersion = [releaseInfo objectForKey:@"version"];  
  48.         NSString *trackViewUrl1 = [releaseInfo objectForKey:@"trackViewUrl"];//地址trackViewUrl  
  49.         trackViewUrl = trackViewUrl1; //地址  
  50.         double doubleUpdateVersion = [latestVersion doubleValue];  
  51.           
  52.           
  53.         //获取当前version版本信息  
  54.         //当前运行程序的版本信息,可以在 mainBundle 里面获取:  
  55.         NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];  
  56.         NSString *currentVersion = [infoDict objectForKey:@"CFBundleVersion"];  
  57.         double doubleCurrentVersion = [currentVersion doubleValue];  
  58.         NSLog(@"doubleCurrentVersion:%f,%f",doubleCurrentVersion,doubleUpdateVersion);  
  59.           
  60.         if (doubleCurrentVersion < doubleUpdateVersion) {  
  61.               
  62.             UIAlertView *alert;  
  63.             alert = [[UIAlertView alloc] initWithTitle:@"app应用名称"  
  64.                                                message:@"有新版本,是否升级!"  
  65.                                               delegate: self  
  66.                                      cancelButtonTitle:@"取消"  
  67.                                      otherButtonTitles: @"升级", nil];  
  68.             alert.tag = 1001;  
  69.             [alert show];  
  70.         }  
  71.           
  72.     }else{  
  73.         //无此应用  
  74.     }  
  75.       
  76. }  
  77.   
  78. //评分  
  79. -(void)appGrade:(NSString *)appleID{  
  80.     appId = appleID;  
  81.     BOOL neverGrade = [[[NSUserDefaults standardUserDefaults] objectForKey:@"neverGrade"] boolValue];  
  82.     if(neverGrade != YES) {  
  83.         //提醒评分   
  84.         UIAlertView *alert;  
  85.         alert = [[UIAlertView alloc] initWithTitle:@"app应用名称"  
  86.                                            message:@"请去appstore给我们评分"  
  87.                                           delegate: self  
  88.                                  cancelButtonTitle:@"取消"  
  89.                                  otherButtonTitles: @"现在去",@"不再提醒 ", nil];  
  90.         alert.tag = 1000;  
  91.         [alert show];  
  92.     }  
  93. }  
  94. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex  
  95. {  
  96.     switch (alertView.tag) {  
  97.         case 1000:  
  98.         {  
  99.             //评分  
  100.             // Never Review Button  
  101.             if (buttonIndex == 2)  
  102.             {  
  103.                 NSString *number = [NSString stringWithFormat:@"%d", YES];  
  104.                 [[NSUserDefaults standardUserDefaults] setObject:number forKey:@"neverGrade"];  
  105.                 [[NSUserDefaults standardUserDefaults] synchronize];  
  106.             }  
  107.             // Review Button  
  108.             else if (buttonIndex == 1)  
  109.             {  
  110.                 NSString *number = [NSString stringWithFormat:@"%d", YES];  
  111.                 [[NSUserDefaults standardUserDefaults] setObject:number forKey:@"neverGrade"];  
  112.                 [[NSUserDefaults standardUserDefaults] synchronize];  
  113.                   
  114.                 //"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=  
  115.                 NSString *str = [NSString stringWithFormat:  
  116.                                  @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@",  
  117.                                  appId ];  
  118.                   
  119.                 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];  
  120.             }  
  121.         }  
  122.             break;  
  123.         case 1001:  
  124.         {  
  125.             //升级              
  126.             if (buttonIndex == 1) {  
  127.                 NSLog(@"%@",trackViewUrl);  
  128.                 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:trackViewUrl]];  
  129.                   
  130.             }  
  131.         }  
  132.             break;  
  133.         default:  
  134.             break;  
  135.     }  
  136.       
  137. }  
  138. @end  

1、更新升级

需要得到当前应用的version版本,获得之前版本的version,比较之下是否需要更新!

当前应用的version:

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

之前应用的version:

需要请求http://itunes.apple.com/lookup?id=appid来获取数据,分析出version;

2、应用评分

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

直接打开这个链接就可以给应用评份;


使用,导入#import "AppUpdateGrade.h"

[cpp]  view plain copy
  1. //升级  
  2.     [[AppUpdateGrade sharedAppupdateGrade]appUpdate:@"appid"];  
  3.     //评分  afterDelay秒  60*1==60分钟,表示1分钟后调用pinfen方法  
  4.     [self performSelector:@selector(pinfen) withObject:self afterDelay:1];  

[cpp]  view plain copy
  1. - (void)pinfen  
  2. {  
  3.     //评分  
  4.     [[AppUpdateGrade sharedAppupdateGrade]appGrade:@"appid"];  
  5. }  


微笑

转载请注明地址!

代码下载链接:http://download.csdn.net/detail/rhljiayou/5870441

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值