iOS开发之诱导用户为自己的App评论功能

移动开发 iOS
苹果市场在分配权重时,都将给APP评论数一定的权重,所以如果没有有道用户评论的功能,会导致用户不会想起要做评论。

"由于我自己的App下载量少,评论也少,出于App的aso优化,想尽办法,而评论是aso里边比较重视的一块,前面的版本都没有诱导用户评论的这一功能,导致有些被动。"

由此自己简单的封装了该功能,下面我们先看看效果图:

弹出试图并没有做什么处理,就是系统的8.0以前用的UIAlertView8.0以上用的UIAlertController

具体的一些算法,都可以看代码,闲话不多说,直接贴码

新建一个NSObject的类命名为LBToAppStore 具体代码如下

.h文件

  1. #import #import @interface LBToAppStore : NSObject{  
  2.     #if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_8_0  
  3.    
  4.     UIAlertView *alertViewTest;  
  5.    
  6.     #else  
  7.    
  8.     UIAlertController *alertController;  
  9.    
  10.     #endif  
  11.    
  12. }  
  13.    
  14. @property (nonatomic,strong) NSString * myAppID;//appID  
  15.    
  16.    
  17.    
  18. - (void)showGotoAppStore:(UIViewController *)VC;  
  19.    
  20. @end 

.m文件

  1. #import "LBToAppStore.h"  
  2.    
  3. @implementation LBToAppStore  
  4.    
  5.    
  6. - (void)showGotoAppStore:(UIViewController *)VC{  
  7.     //当前版本号  
  8.     NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];  
  9.     float appVersion = [[infoDictionary objectForKey:@"CFBundleShortVersionString"] floatValue];  
  10.     //userDefaults里的天数  
  11.     NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];  
  12.     int udtheDays = [[userDefaults objectForKey:@"theDays"] intValue];  
  13.     //userDefaults里的版本号  
  14.     float udAppVersion = [[userDefaults objectForKey:@"appVersion"] intValue];  
  15.     //userDefaults里用户上次的选项  
  16.     int udUserChoose = [[userDefaults objectForKey:@"userOptChoose"] intValue];  
  17.     //时间戳的天数  
  18.     NSTimeInterval interval = [[NSDate date] timeIntervalSince1970];  
  19.     int daySeconds = 24 * 60 * 60;  
  20.     NSInteger theDays = interval / daySeconds;  
  21.    
  22.     //版本升级之后的处理,全部规则清空,开始弹窗  
  23.     if (udAppVersion && appVersion>udAppVersion) {  
  24.         [userDefaults removeObjectForKey:@"theDays"];  
  25.         [userDefaults removeObjectForKey:@"appVersion"];  
  26.         [userDefaults removeObjectForKey:@"userOptChoose"];  
  27.         [self alertUserCommentView:VC];  
  28.     }  
  29.     //1,从来没弹出过的  
  30.     //2,用户选择????我要吐槽,7天之后再弹出  
  31.     //3,用户选择????残忍拒绝后,7天内,每过1天会弹一次  
  32.     //4,用户选择????残忍拒绝的30天后,才会弹出  
  33.     else if (!udUserChoose ||  
  34.     (udUserChoose==2 && theDays-udtheDays>7) ||  
  35.     (udUserChoose>=3 && theDays-udtheDaysudUserChoose-3) ||  
  36.     (udUserChoose>=3 && theDays-udtheDays>30))  
  37.     {  
  38.         [self alertUserCommentView:VC];  
  39.    
  40.     }  
  41.    
  42. }  
  43.    
  44. -(void)alertUserCommentView:(UIViewController *)VC{  
  45.    
  46.     if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {  
  47.    
  48.     NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];  
  49.     //当前时间戳的天数  
  50.     NSTimeInterval interval = [[NSDate date] timeIntervalSince1970];  
  51.     int daySeconds = 24 * 60 * 60;  
  52.     NSInteger theDays = interval / daySeconds;  
  53.     //当前版本号  
  54.     NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];  
  55.     float appVersion = [[infoDictionary objectForKey:@"CFBundleShortVersionString"] floatValue];  
  56.     //userDefaults里版本号  
  57.     float udAppVersion = [[userDefaults objectForKey:@"appVersion"] intValue];  
  58.     //userDefaults里用户选择项目  
  59.     int udUserChoose = [[userDefaults objectForKey:@"userOptChoose"] intValue];  
  60.     //userDefaults里用户天数  
  61.     int udtheDays = [[userDefaults objectForKey:@"theDays"] intValue];  
  62.    
  63.     //当前版本比userDefaults里版本号高  
  64.     if (appVersion>udAppVersion) {  
  65.         [userDefaults setObject:[NSString stringWithFormat:@"%f",appVersion] forKey:@"appVersion"];  
  66.     }  
  67.    
  68.     alertController = [UIAlertController alertControllerWithTitle:@"致开发者的一封信" message:@"有了您的支持才能更好的为您服务,提供更加优质的,更加适合您的App,当然您也可以直接反馈问题给到我们" preferredStyle:(UIAlertControllerStyleAlert)];  
  69.    
  70.     UIAlertAction *refuseAction = [UIAlertAction actionWithTitle:@"????残忍拒绝" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {  
  71.    
  72.     [userDefaults setObject:@"1" forKey:@"userOptChoose"];  
  73.     [userDefaults setObject:[NSString stringWithFormat:@"%d",(int)theDays] forKey:@"theDays"];  
  74.     }];  
  75.    
  76.     UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"????好评赞赏" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {  
  77.    
  78.     [userDefaults setObject:@"2" forKey:@"userOptChoose"];  
  79.     [userDefaults setObject:[NSString stringWithFormat:@"%d",(int)theDays] forKey:@"theDays"];  
  80.    
  81.     NSString *str = [NSString stringWithFormat:  
  82.     @"https://itunes.apple.com/cn/app/id%@?mt=8",  
  83.     self.myAppID ];  
  84.    
  85.     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];  
  86.    
  87.     }];  
  88.    
  89.     UIAlertAction *showAction = [UIAlertAction actionWithTitle:@"????我要吐槽" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {  
  90.    
  91.     if (udUserChoose30) {  
  92.     [userDefaults setObject:@"3" forKey:@"userOptChoose"];  
  93.     [userDefaults setObject:[NSString stringWithFormat:@"%d",(int)theDays] forKey:@"theDays"];  
  94.     }else{  
  95.     [userDefaults setObject:[NSString stringWithFormat:@"%d",(int)(theDays-udtheDays+3)] forKey:@"userOptChoose"];  
  96.     }  
  97.     NSString *str = [NSString stringWithFormat:  
  98.     @"https://itunes.apple.com/cn/app/id%@?mt=8",  
  99.     self.myAppID ];  
  100.    
  101.     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];  
  102.     }];  
  103.    
  104.    
  105.     [alertController addAction:refuseAction];  
  106.     [alertController addAction:okAction];  
  107.     [alertController addAction:showAction];  
  108.    
  109.     //        NSLog(@"%@",[userDefaults objectForKey:@"appVersion"]);  
  110.     //        NSLog(@"%@",[userDefaults objectForKey:@"userOptChoose"]);  
  111.     //        NSLog(@"%@",[userDefaults objectForKey:@"theDays"]);  
  112.    
  113.     [VC presentViewController:alertController animated:YES completion:nil];  
  114.    
  115.     }else{  
  116.         #if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_8_0  
  117.         alertViewTest = [[UIAlertView alloc] initWithTitle:@"致开发者的一封信" message:@"有了您的支持才能更好的为您服务,提供更加优质的,更加适合您的App,当然您也可以直接反馈问题给到我们" delegate:self cancelButtonTitle:@"????残忍拒绝" otherButtonTitles:@"????好评赞赏",@"????我要吐槽", nil];  
  118.         [alertViewTest show];  
  119.         #endif  
  120.     }  
  121.    
  122. }  
  123.    
  124. #if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_8_0  
  125.    
  126. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{  
  127.    
  128.     NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];  
  129.     //当前时间戳的天数  
  130.     NSTimeInterval interval = [[NSDate date] timeIntervalSince1970];  
  131.     int daySeconds = 24 * 60 * 60;  
  132.     NSInteger theDays = interval / daySeconds;  
  133.     //当前版本号  
  134.     NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];  
  135.     float appVersion = [[infoDictionary objectForKey:@"CFBundleShortVersionString"] floatValue];  
  136.     //userDefaults里版本号  
  137.     float udAppVersion = [[userDefaults objectForKey:@"appVersion"] intValue];  
  138.     //userDefaults里用户选择项目  
  139.     int udUserChoose = [[userDefaults objectForKey:@"userOptChoose"] intValue];  
  140.     //userDefaults里用户天数  
  141.     int udtheDays = [[userDefaults objectForKey:@"theDays"] intValue];  
  142.    
  143.     //当前版本比userDefaults里版本号高  
  144.     if (appVersion>udAppVersion) {  
  145.         [userDefaults setObject:[NSString stringWithFormat:@"%f",appVersion] forKey:@"appVersion"];  
  146.     }  
  147.    
  148.     switch (buttonIndex) {  
  149.         case 0: //残忍的拒绝  
  150.         if (udUserChoose30) {  
  151.             [userDefaults setObject:@"3" forKey:@"userOptChoose"];  
  152.             [userDefaults setObject:[NSString stringWithFormat:@"%d",(int)theDays] forKey:@"theDays"];  
  153.         }else{  
  154.             [userDefaults setObject:[NSString stringWithFormat:@"%d",(int)(theDays-udtheDays+3)] forKey:@"userOptChoose"];  
  155.         }  
  156.         break;  
  157.         case 1:{ //好评  
  158.             [userDefaults setObject:@"1" forKey:@"userOptChoose"];  
  159.             [userDefaults setObject:[NSString stringWithFormat:@"%d",(int)theDays] forKey:@"theDays"];  
  160.             NSString *str = [NSString stringWithFormat:  
  161.             @"https://itunes.apple.com/cn/app/id%@?mt=8",  
  162.             self.myAppID ];  
  163.    
  164.             [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];  
  165.         }  
  166.         break;  
  167.         case 2:{ //不好用,我要提意见  
  168.             [userDefaults setObject:@"2" forKey:@"userOptChoose"];  
  169.             [userDefaults setObject:[NSString stringWithFormat:@"%d",(int)theDays] forKey:@"theDays"];  
  170.             NSString *str = [NSString stringWithFormat:  
  171.             @"https://itunes.apple.com/cn/app/id%@?mt=8",  
  172.             self.myAppID ];  
  173.    
  174.             [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];  
  175.         }  
  176.         break;  
  177.    
  178.         default:  
  179.         break;  
  180.         }  
  181.     //    NSLog(@"%@",[userDefaults objectForKey:@"appVersion"]);  
  182.     //    NSLog(@"%@",[userDefaults objectForKey:@"userOptChoose"]);  
  183.     //    NSLog(@"%@",[userDefaults objectForKey:@"theDays"]);  
  184.    
  185. }  
  186.    
  187. #endif  
  188.    
  189.    
  190. @end 

具体使用方法如下:

  1. #import "ViewController.h"  
  2. #import "LBToAppStore.h"  
  3. @interface ViewController ()  
  4.    
  5. @end  
  6.    
  7. @implementation ViewController  
  8.    
  9. - (void)viewDidLoad {  
  10.     [super viewDidLoad];  
  11.     // Do any additional setup after loading the view, typically from a nib.  
  12. }  
  13.    
  14. -(void)viewDidAppear:(BOOL)animated{  
  15.    
  16.     //用户好评系统  
  17.     LBToAppStore *toAppStore = [[LBToAppStore alloc]init];  
  18.     toAppStore.myAppID = @"1067787090";  
  19.     [toAppStore showGotoAppStore:self];  
  20.    
  21. }  
  22.    
  23.    
  24. @end 

 

责任编辑:陈琳 来源: CocoaChina
相关推荐

2013-05-14 10:07:13

谷歌

2022-02-13 23:12:34

网络钓鱼谷歌Google

2020-08-21 10:41:07

微信隐藏点评评论

2014-12-19 10:11:37

微信公众号

2017-12-25 14:59:47

APP架构iOS协议

2021-09-30 09:52:21

App StoreiOS苹果

2021-05-10 10:00:23

iOS苹果系统

2013-07-05 13:48:47

App

2013-12-20 09:33:36

iOS 7用户界面

2012-04-29 10:56:34

APP

2021-03-15 13:30:51

MongoDBMySQL数据库

2021-08-21 15:58:53

iOS 15天气APP苹果

2021-07-13 08:01:43

iOS 15果粉苹果

2012-04-29 11:13:14

APP

2021-10-21 10:03:09

鸿蒙HarmonyOS应用

2014-05-04 17:51:11

应用汇升级互动平台

2009-09-21 09:18:46

2018-12-12 15:30:28

Google LensiOSAPP

2014-07-23 13:17:53

iOSUITextField

2011-12-03 21:23:56

App
点赞
收藏

51CTO技术栈公众号