iOS development: Inducing users to comment on your app

iOS development: Inducing users to comment on your app

"Since my own app has few downloads and comments, I tried every possible way to optimize the app for ASO, and comments are a relatively important part of ASO. The previous versions did not have the function of inducing users to comment, which made it somewhat passive."

Therefore, I simply encapsulated this function. Let's take a look at the effect diagram first:

The pop-up view does not do anything, that is, the UIAlertView used before 8.0 of the system and the UIAlertController used after 8.0

For some specific algorithms, you can see the code. Without further ado, I will just post the code.

Create a new NSObject class named LBToAppStore. The specific code is as follows

.h files

  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 file

  1. #import "LBToAppStore.h"  
  2.    
  3. @implementation LBToAppStore
  4.    
  5.    
  6. - ( void )showGotoAppStore:(UIViewController *)VC{
  7.      //Current version number  
  8. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  9.      float appVersion = [[infoDictionary objectForKey:@ "CFBundleShortVersionString" ] floatValue];
  10.      //Number of days in userDefaults  
  11. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
  12.      int udtheDays = [[userDefaults objectForKey:@ "theDays" ] intValue];
  13.      //Version number in userDefaults  
  14.      float udAppVersion = [[userDefaults objectForKey:@ "appVersion" ] intValue];
  15.      //The user's last option in userDefaults  
  16.      int udUserChoose = [[userDefaults objectForKey:@ "userOptChoose" ] intValue];
  17.      //Timestamp days  
  18. NSTimeInterval interval = [[NSDate date] timeIntervalSince1970];
  19.      int daySeconds = 24 * 60 * 60;
  20. NSInteger theDays = interval / daySeconds;
  21.    
  22.      //Processing after version upgrade, clear all rules and start pop-up window  
  23.      if (udAppVersion && appVersion>udAppVersion) {
  24. [userDefaults removeObjectForKey:@ "theDays" ];
  25. [userDefaults removeObjectForKey:@ "appVersion" ];
  26. [userDefaults removeObjectForKey:@ "userOptChoose" ];
  27. [self alertUserCommentView:VC];
  28. }
  29.      //1, never popped up  
  30.      //2, user selects ???? I want to complain, pop up again after 7 days  
  31.      //3. After the user selects ????Cruel Rejection, the pop-up will appear every day for 7 days.  
  32.      //4, the pop-up window will appear 30 days after the user chooses "cruel rejection"  
  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.      //The number of days of the current timestamp  
  50. NSTimeInterval interval = [[NSDate date] timeIntervalSince1970];
  51.      int daySeconds = 24 * 60 * 60;
  52. NSInteger theDays = interval / daySeconds;
  53.      //Current version number  
  54. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  55.      float appVersion = [[infoDictionary objectForKey:@ "CFBundleShortVersionString" ] floatValue];
  56.      //Version number in userDefaults  
  57.      float udAppVersion = [[userDefaults objectForKey:@ "appVersion" ] intValue];
  58.      //User selection item in userDefaults  
  59.      int udUserChoose = [[userDefaults objectForKey:@ "userOptChoose" ] intValue];
  60.      //User days in userDefaults  
  61.      int udtheDays = [[userDefaults objectForKey:@ "theDays" ] intValue];
  62.    
  63.      //The current version is higher than the version number in userDefaults  
  64.      if (appVersion>udAppVersion) {
  65. [userDefaults setObject:[NSString stringWithFormat:@ "%f" ,appVersion] forKey:@ "appVersion" ];
  66. }
  67.    
  68. alertController = [UIAlertController alertControllerWithTitle:@ "A letter to developers" message:@ "With your support, we can better serve you and provide you with better quality apps that are more suitable for you. Of course, you can also directly give us feedback on the problem" preferredStyle:(UIAlertControllerStyleAlert)];
  69.    
  70. UIAlertAction *refuseAction = [UIAlertAction actionWithTitle:@ "????Cruel Refuse" 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:@ "????Good reviews and appreciation" 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:@ "????I want to complain" 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:@ "A letter to developers" message:@ "With your support, we can better serve you and provide you with better quality apps that are more suitable for you. Of course, you can also directly give us feedback on the problem" delegate:self cancelButtonTitle:@ "????Cruel rejection" otherButtonTitles:@ "????Good reviews" ,@ "????I want to complain" , 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.      //The number of days of the current timestamp  
  130. NSTimeInterval interval = [[NSDate date] timeIntervalSince1970];
  131.      int daySeconds = 24 * 60 * 60;
  132. NSInteger theDays = interval / daySeconds;
  133.      //Current version number  
  134. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  135.      float appVersion = [[infoDictionary objectForKey:@ "CFBundleShortVersionString" ] floatValue];
  136.      //Version number in userDefaults  
  137.      float udAppVersion = [[userDefaults objectForKey:@ "appVersion" ] intValue];
  138.      //User selection item in userDefaults  
  139.      int udUserChoose = [[userDefaults objectForKey:@ "userOptChoose" ] intValue];
  140.      //User days in userDefaults  
  141.      int udtheDays = [[userDefaults objectForKey:@ "theDays" ] intValue];
  142.    
  143.      //The current version is higher than the version number in userDefaults  
  144.      if (appVersion>udAppVersion) {
  145. [userDefaults setObject:[NSString stringWithFormat:@ "%f" ,appVersion] forKey:@ "appVersion" ];
  146. }
  147.    
  148.      switch (buttonIndex) {
  149.          case 0: //Cruel rejection  
  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:{ //Good reviews  
  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:{ //It doesn't work well, I want to make suggestions  
  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

The specific usage is as follows:

  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.      //User praise system  
  17. LBToAppStore *toAppStore = [[LBToAppStore alloc]init];
  18. toAppStore.myAppID = @ "1067787090" ;
  19. [toAppStore showGotoAppStore:self];
  20.    
  21. }
  22.    
  23.    
  24. @end

<<:  【Huang Xiaoqing】The first Chinese business leader won the IEEE CQR Chairman Award

>>:  Understanding Android naming conventions

Recommend

The three core techniques for private domain traffic operations!

I read two books before the Chinese New Year, bot...

What is LSD? It once made Steve Jobs addicted

Lysergic acid diethylamide, also known as "l...

Flu, parasites, cancer...you heard it right, dinosaurs can get sick too!

The weather is getting colder Everyone must keep ...

How to write a competitive proposal so that users will choose your product?

Some time ago, the P2P industry experienced a sma...

Why is pottery fired at 1000°C and porcelain fired at 1200°C?

Ceramics, an art form that combines traditional C...

Data operations: 8 essential data analysis methods for operations!

When it comes to data analysis, people often thin...

New energy vehicle promotion catalog review market sales may be affected

Yesterday, the official website of China Machiner...

Google launches ARCore, an augmented reality SDK, to compete with Apple's ARKit

[[201618]] On August 30, Google announced the lau...

“Tik Tok Likers” earn over 10,000 yuan a month, is it reliable?

"Making money from those who want to make mo...