iOS开发之诱导用户为自己的App评论功能
2016-05-18 00:00
597 查看
摘要: iOS开发之 诱导用户为自己的App评论功能
"由于我自己的App下载量少,评论也少,出于App的aso优化,想尽办法,而评论是aso里边比较重视的一块,前面的版本都没有诱导用户评论的这一功能,导致有些被动。"
由此自己简单的封装了该功能,下面我们先看看效果图:
弹出试图并没有做什么处理,就是系统的8.0以前用的
具体的一些算法,都可以看代码,闲话不多说,直接贴码
新建一个NSObject的类命名为
具体使用方法如下:
"由于我自己的App下载量少,评论也少,出于App的aso优化,想尽办法,而评论是aso里边比较重视的一块,前面的版本都没有诱导用户评论的这一功能,导致有些被动。"
由此自己简单的封装了该功能,下面我们先看看效果图:
弹出试图并没有做什么处理,就是系统的8.0以前用的
UIAlertView8.0以上用的
UIAlertController
具体的一些算法,都可以看代码,闲话不多说,直接贴码
新建一个NSObject的类命名为
LBToAppStore具体代码如下
.h文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #import #import @interface LBToAppStore : NSObject{ #if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_8_0 UIAlertView *alertViewTest; #else UIAlertController *alertController; #endif } @property (nonatomic,strong) NSString * myAppID; //appID - (void)showGotoAppStore:(UIViewController *)VC; @end |
.m文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | #import "LBToAppStore.h" @implementation LBToAppStore - (void)showGotoAppStore:(UIViewController *)VC{ //当前版本号 NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; float appVersion = [[infoDictionary objectForKey:@ "CFBundleShortVersionString" ] floatValue]; //userDefaults里的天数 NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; int udtheDays = [[userDefaults objectForKey:@ "theDays" ] intValue]; //userDefaults里的版本号 float udAppVersion = [[userDefaults objectForKey:@ "appVersion" ] intValue]; //userDefaults里用户上次的选项 int udUserChoose = [[userDefaults objectForKey:@ "userOptChoose" ] intValue]; //时间戳的天数 NSTimeInterval interval = [[NSDate date] timeIntervalSince1970]; int daySeconds = 24 * 60 * 60; NSInteger theDays = interval / daySeconds; //版本升级之后的处理,全部规则清空,开始弹窗 if (udAppVersion && appVersion>udAppVersion) { [userDefaults removeObjectForKey:@ "theDays" ]; [userDefaults removeObjectForKey:@ "appVersion" ]; [userDefaults removeObjectForKey:@ "userOptChoose" ]; [self alertUserCommentView:VC]; } //1,从来没弹出过的 //2,用户选择????我要吐槽,7天之后再弹出 //3,用户选择????残忍拒绝后,7天内,每过1天会弹一次 //4,用户选择????残忍拒绝的30天后,才会弹出 else if (!udUserChoose || (udUserChoose==2 && theDays-udtheDays>7) || (udUserChoose>=3 && theDays-udtheDaysudUserChoose-3) || (udUserChoose>=3 && theDays-udtheDays>30)) { [self alertUserCommentView:VC]; } } -(void)alertUserCommentView:(UIViewController *)VC{ if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; //当前时间戳的天数 NSTimeInterval interval = [[NSDate date] timeIntervalSince1970]; int daySeconds = 24 * 60 * 60; NSInteger theDays = interval / daySeconds; //当前版本号 NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; float appVersion = [[infoDictionary objectForKey:@ "CFBundleShortVersionString" ] floatValue]; //userDefaults里版本号 float udAppVersion = [[userDefaults objectForKey:@ "appVersion" ] intValue]; //userDefaults里用户选择项目 int udUserChoose = [[userDefaults objectForKey:@ "userOptChoose" ] intValue]; //userDefaults里用户天数 int udtheDays = [[userDefaults objectForKey:@ "theDays" ] intValue]; //当前版本比userDefaults里版本号高 if (appVersion>udAppVersion) { [userDefaults setObject:[NSString stringWithFormat:@ "%f" ,appVersion] forKey:@ "appVersion" ]; } alertController = [UIAlertController alertControllerWithTitle:@ "致开发者的一封信" message:@ "有了您的支持才能更好的为您服务,提供更加优质的,更加适合您的App,当然您也可以直接反馈问题给到我们" preferredStyle:(UIAlertControllerStyleAlert)]; UIAlertAction *refuseAction = [UIAlertAction actionWithTitle:@ "????残忍拒绝" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) { [userDefaults setObject:@ "1" forKey:@ "userOptChoose" ]; [userDefaults setObject:[NSString stringWithFormat:@ "%d" ,(int)theDays] forKey:@ "theDays" ]; }]; UIAlertAction *okAction = [UIAlertAction actionWithTitle:@ "????好评赞赏" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) { [userDefaults setObject:@ "2" forKey:@ "userOptChoose" ]; [userDefaults setObject:[NSString stringWithFormat:@ "%d" ,(int)theDays] forKey:@ "theDays" ]; NSString *str = [NSString stringWithFormat: @ "https://itunes.apple.com/cn/app/id%@?mt=8" , self.myAppID ]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]]; }]; UIAlertAction *showAction = [UIAlertAction actionWithTitle:@ "????我要吐槽" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) { if (udUserChoose30) { [userDefaults setObject:@ "3" forKey:@ "userOptChoose" ]; [userDefaults setObject:[NSString stringWithFormat:@ "%d" ,(int)theDays] forKey:@ "theDays" ]; } else { [userDefaults setObject:[NSString stringWithFormat:@ "%d" ,(int)(theDays-udtheDays+3)] forKey:@ "userOptChoose" ]; } NSString *str = [NSString stringWithFormat: @ "https://itunes.apple.com/cn/app/id%@?mt=8" , self.myAppID ]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]]; }]; [alertController addAction:refuseAction]; [alertController addAction:okAction]; [alertController addAction:showAction]; //NSLog(@"%@",[userDefaults objectForKey:@"appVersion"]); //NSLog(@"%@",[userDefaults objectForKey:@"userOptChoose"]); //NSLog(@"%@",[userDefaults objectForKey:@"theDays"]); [VC presentViewController:alertController animated:YES completion:nil]; } else { #if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_8_0 alertViewTest = [[UIAlertView alloc] initWithTitle:@ "致开发者的一封信" message:@ "有了您的支持才能更好的为您服务,提供更加优质的,更加适合您的App,当然您也可以直接反馈问题给到我们" delegate:self cancelButtonTitle:@ "????残忍拒绝" otherButtonTitles:@ "????好评赞赏" ,@ "????我要吐槽" , nil]; [alertViewTest show]; #endif } } #if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_8_0 -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; //当前时间戳的天数 NSTimeInterval interval = [[NSDate date] timeIntervalSince1970]; int daySeconds = 24 * 60 * 60; NSInteger theDays = interval / daySeconds; //当前版本号 NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; float appVersion = [[infoDictionary objectForKey:@ "CFBundleShortVersionString" ] floatValue]; //userDefaults里版本号 float udAppVersion = [[userDefaults objectForKey:@ "appVersion" ] intValue]; //userDefaults里用户选择项目 int udUserChoose = [[userDefaults objectForKey:@ "userOptChoose" ] intValue]; //userDefaults里用户天数 int udtheDays = [[userDefaults objectForKey:@ "theDays" ] intValue]; //当前版本比userDefaults里版本号高 if (appVersion>udAppVersion) { [userDefaults setObject:[NSString stringWithFormat:@ "%f" ,appVersion] forKey:@ "appVersion" ]; } switch (buttonIndex) { case 0: //残忍的拒绝 if (udUserChoose30) { [userDefaults setObject:@ "3" forKey:@ "userOptChoose" ]; [userDefaults setObject:[NSString stringWithFormat:@ "%d" ,(int)theDays] forKey:@ "theDays" ]; } else { [userDefaults setObject:[NSString stringWithFormat:@ "%d" ,(int)(theDays-udtheDays+3)] forKey:@ "userOptChoose" ]; } break ; case 1:{ //好评 [userDefaults setObject:@ "1" forKey:@ "userOptChoose" ]; [userDefaults setObject:[NSString stringWithFormat:@ "%d" ,(int)theDays] forKey:@ "theDays" ]; NSString *str = [NSString stringWithFormat: @ "https://itunes.apple.com/cn/app/id%@?mt=8" , self.myAppID ]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]]; } break ; case 2:{ //不好用,我要提意见 [userDefaults setObject:@ "2" forKey:@ "userOptChoose" ]; [userDefaults setObject:[NSString stringWithFormat:@ "%d" ,(int)theDays] forKey:@ "theDays" ]; NSString *str = [NSString stringWithFormat: @ "https://itunes.apple.com/cn/app/id%@?mt=8" , self.myAppID ]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]]; } break ; default : break ; } //NSLog(@"%@",[userDefaults objectForKey:@"appVersion"]); //NSLog(@"%@",[userDefaults objectForKey:@"userOptChoose"]); //NSLog(@"%@",[userDefaults objectForKey:@"theDays"]); } #endif @end |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #import "ViewController.h" #import "LBToAppStore.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [ super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } -(void)viewDidAppear:(BOOL)animated{ //用户好评系统 LBToAppStore *toAppStore = [[LBToAppStore alloc]init]; toAppStore.myAppID = @ "1067787090" ; [toAppStore showGotoAppStore:self]; } @end |
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 讲解iOS开发中基本的定位功能实现
- iOS中定位当前位置坐标及转换为火星坐标的方法
- js判断客户端是iOS还是Android等移动终端的方法
- iOS应用开发中AFNetworking库的常用HTTP操作方法小结
- iOS应用中UISearchDisplayController搜索效果的用法
- IOS开发环境windows化攻略
- iOS应用中UITableView左滑自定义选项及批量删除的实现
- 浅析iOS应用开发中线程间的通信与线程安全问题
- 检测iOS设备是否越狱的方法
- .net平台推送ios消息的实现方法
- 探讨Android与iOS,我们将何去何从?
- Android、iOS和Windows Phone中的推送技术详解
- iOS推送的那些事