"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 - #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;
-
-
-
- - ( void )showGotoAppStore:(UIViewController *)VC;
-
- @end
.m file - #import "LBToAppStore.h"
-
- @implementation LBToAppStore
-
-
- - ( void )showGotoAppStore:(UIViewController *)VC{
-
- NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
- float appVersion = [[infoDictionary objectForKey:@ "CFBundleShortVersionString" ] floatValue];
-
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- int udtheDays = [[userDefaults objectForKey:@ "theDays" ] intValue];
-
- float udAppVersion = [[userDefaults objectForKey:@ "appVersion" ] intValue];
-
- 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];
- }
-
-
-
-
- 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];
-
- float udAppVersion = [[userDefaults objectForKey:@ "appVersion" ] intValue];
-
- int udUserChoose = [[userDefaults objectForKey:@ "userOptChoose" ] intValue];
-
- int udtheDays = [[userDefaults objectForKey:@ "theDays" ] intValue];
-
-
- if (appVersion>udAppVersion) {
- [userDefaults setObject:[NSString stringWithFormat:@ "%f" ,appVersion] forKey:@ "appVersion" ];
- }
-
- 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)];
-
- UIAlertAction *refuseAction = [UIAlertAction actionWithTitle:@ "????Cruel Refuse" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {
-
- [userDefaults setObject:@ "1" forKey:@ "userOptChoose" ];
- [userDefaults setObject:[NSString stringWithFormat:@ "%d" ,( int )theDays] forKey:@ "theDays" ];
- }];
-
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:@ "????Good reviews and appreciation" 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:@ "????I want to complain" 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];
-
-
-
-
-
- [VC presentViewController:alertController animated:YES completion:nil];
-
- } else {
- #if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_8_0
- 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];
- [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];
-
- float udAppVersion = [[userDefaults objectForKey:@ "appVersion" ] intValue];
-
- int udUserChoose = [[userDefaults objectForKey:@ "userOptChoose" ] intValue];
-
- int udtheDays = [[userDefaults objectForKey:@ "theDays" ] intValue];
-
-
- 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 ;
- }
-
-
-
-
- }
-
- #endif
-
-
- @end
The specific usage is as follows: - #import "ViewController.h"
- #import "LBToAppStore.h"
- @interface ViewController ()
-
- @end
-
- @implementation ViewController
-
- - ( void )viewDidLoad {
- [ super viewDidLoad];
-
- }
-
- -( void )viewDidAppear:(BOOL)animated{
-
-
- LBToAppStore *toAppStore = [[LBToAppStore alloc]init];
- toAppStore.myAppID = @ "1067787090" ;
- [toAppStore showGotoAppStore:self];
-
- }
-
-
- @end
|