allluckly.cn.jpg
“由於我自己的App下載量少,評論也少,出於App的aso優化,想盡辦法,而評論是aso裡邊比較重視的一塊,前面的版本都沒有誘導使用者評論的這一功能,導致有些被動。”
由此自己簡單的封裝了該功能,下面我們先看看效果圖:
1.png
彈出試圖並沒有做什麼處理,就是系統的8.0以前用的UIAlertView
8.0以上用的UIAlertController
具體的一些演算法,都可以看程式碼,閒話不多說,直接貼碼,?
新建一個NSObject的類命名為LBToAppStore
具體程式碼如下
.h檔案
1 2 3 4 5 6 7 8 9 |
#import #import @interface LBToAppStore : NSObject { #if __IPHONE_OS_VERSION_MAX_ALLOWED |
.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 |
#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 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 |
如對你有幫助,請不要吝惜你的star和喜歡哦!
版權歸©Bison所有 如需轉載請保留原文超連結地址!否則後果自負!