“因为自己的app下载量少,评论少,所以我尽量优化app的aso,而评论是aso中比较重要的一个部分,之前的版本没有诱导用户评论的功能,导致有些被动”所以我就简单封装了这个功能,先来看看效果图:弹窗尝试什么都不做,也就是8.0之前的系统使用的UIAlertView8.0及以上的一些特定算法可以使用看看代码处,闲话少说,直接贴代码新建一个NSObject类,名称为LBToAppStore,具体代码如下。h文件#import#import@interfaceLBToAppStore:NSObject{#if__IPHONE_OS_VERSION_MAX_ALLOWED<__IPHONE_8_0UIAlertView*alertViewTest;#elseUIAlertController*alertController;#endif}@property(nonatomic,strong)NSString*myAppID;//appID-(void)showGotoAppStore:(UIViewController*)VC;@end.mfile#import"LBToAppStore.h"@implementationLBToAppStore-(void)showGotoAppStore:(UIViewController*)VC{//当前版本号NSDictionary*infoDictionary=[[NSBundlemainBundle]infoDictionary];floatappVersion=[[infoDictionaryobjectForKey:@"CFBundleShortVersionString"]floatValue];//userDefaults中的天数NSUserDefaults*userDefaults=[NSUserDefaultsstandardUserDefaults=[NSUserDefaultsstandardUserDeintfaults];[userDefaultsobjectForKey:@"theDays"]intValue];//userDefaults中的版本号floatudAppVersion=[[userDefaultsobjectForKey:@"appVersion"]intValue];//用户在userDefaults中的最后一个选项intudUserChoose=[[userDefaultsobjectForKey:@"userOptChoose"]intValue];//时间戳的天数NSTimeIntervalinterval=[[NSDatedate]timeIntervalSince1970];intdaySeconds=24*60*60;NSIntegertheDays=间隔/天秒;//版本升级后处理,清空所有规则,开启弹窗if(udAppVersion&&appVersion>udAppVersion){[userDefaultsremoveObjectForKey:@"theDays"];[userDefaultsremoveObjectForKey:@"appVersion"];[userDefaultsremoveObjectForKey:@"userOptChoose"];[selfalertUserCommentView:VC];}//1,从不弹出//2,用户选择????我要投诉,7天后才会弹出//3,用户选择????残忍拒绝后,7天内,每天弹出一次。//4,用户选择????残酷拒绝30天后,elseif(!udUserChoose||(udUserChoose==2&&theDays-udtheDays>7)||(udUserChoose>=3&&theDays-udtheDaysudUserChoose-3)||(udUserChoose>=3&&theDays-udtheDays>30)){[selfalertUserCommentView:VC];}}-(void)alertUserCommentView:(UIViewController*)VC{if([[[UIDevicecurrentDevice]systemVersion]floatValue]>=8.0){NSUserDefaults*userDefaults=[NSUserDefaultsstandardUserDefaults];//当前时间戳的天数NSTimeIntervalinterval=[[NSDatedate]timeIntervalSince1970];intdaySeconds=24*60*60;NSIntegertheDays=间隔/天秒;//当前版本号NSDictionary*infoDictionary=[[NSBundlemainBundle]infoDictionary];floatappVersion=[[infoDictionaryobjectForKey:@"CFBundleShortVersionString"];floatDeuserValue版本号在floatudAppVersion=[[userDefaultsobjectForKey:@"appVersion"]intValue];//userDefaultsintudtheDays=[[userDefaultsobjectForKey:intudtheDays=[[userDefaultsobjectForKey:@"theDays"]intValue];//当前版本高于userDefaults中的版本号if(appVersion>udAppVersion){[userDefaultssetObject:[NSStringstringWithFormat:@"%f",appVersion]forKey:@"appVersion"];}啤酒rtController=[UIAlertControlleralertControllerWithTitle:@"致开发者的一封信"message:@"有了您的支持,我们才能更好地为您服务,提供更优质更适合您的App。当然您也可以直接反馈给我们"preferredStyle:(UIAlertControllerStyleAlert)];UIAlertAction*refuseAction=[UIAlertActionactionWithTitle:@"????残酷拒绝"style:(UIAlertActionStyleDefault)handler:^(UIAlertAction*action){[userDefaultssetObject:@"1"forKey:@"userOptChoose"];[userDefaultssetObject:[NSStringstringWithFormat:@"%d",(int)theDays]forKey:@"theDays"];}];UIAlertAction*okAction=[UIAlertActionactionWithTitle:@"????赞赏"style:(UIAlertActionStyleDefault)handler:^(UIAlertAction*action){[userDefaultssetObject:@"2"forKey:@"userOptChoose"];[userDefaultssetObject:[NSStringstringWithFormat:@"%d",(int)theDays]forKey:@"theDays"];NSString*str=[NSStringstringWithFormat:@"https://itunes.apple.com/cn/app/id%@?mt=8",self.myAppID];[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:str]];}];UIAlertAction*showAction=[UIAlertActionactionWithTitle:@"????我要吐槽"style:(UIAlertActionStyleDefault)handler:^(UIAlertAction*action){if(udUserChoose30){[userDefaultssetObject:@"3"forKey:@"userOptChoose"];[userDefaultssetObject:[NSStringstringWithFormat:@"%d",(int)theDays]forKey:@"theDays"];}else{[userDefaultssetObject:[NSStringstringWithFormat:@"%d",(int)(theDays-udtheDays+3)]forKey:@"userOptChoose"];}NSString*str=[NSStringstringWithFormat:@"https://itunes.apple.com/cn/app/id%@?mt=8",self.myAppID];[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:str]];}];[alertControlleraddAction:refuseAction];[alertControlleraddAction:okAction];[alertControlleraddAction:showAction];//NSLog(@"%@",[userDefaultsobjectForKey:@"appVersion"]);//NSLog(@"%@",[userDefaultsobjectForKey:@"userOptChoose"]);//NSLog(@"%@",[userDefaultsobjectForKey:@"theDays"]);[VCpresentViewController:alertControlleranimated:YEScompletion:nil];}else{#if__IPHONE_OS_VERSION_MAX_ALLOWED<__IPHONE_8_0alertViewTest=[[UIAlertViewalloc]initWithTitle:@"致开发者的一封信"message:@"有您的支持,我们才能更好地为您服务,为您提供更优质更适合您的App。当然,您也可以直接反馈给我们“delegate:selfcancelButtonTitle:@”????残忍拒绝“otherButtonTitles:@”????表扬和赞赏,@“????我要投诉”,nil];[alertViewTestshow];#endif}}#if__IPHONE_OS_VERSION_MAX_ALLOWED<__IPHONE_8_0-(void)alertView:(UIAlertView*)alertViewclickedButtonAtIndex:(NSInteger)buttonIndex{NSUserDefaults*userDefaults=[NSUserDefaultsstandardUserDefaults];//当时间间隔的天数NSTimeIntervalinterval=[[NSDatedate]timeIntervalSince1970];intdaySeconds=24*60*60;NSIntegertheDays=间隔/天秒;//当前版本号NSDictionary*infoDictionary=[[NSBundlemainBundle]infoDictiona瑞];floatappVersion=[[infoDictionaryobjectForKey:@"CFBundleShortVersionString"]floatValue];//userDefaults中的版本号floatudAppVersion=[[userDefaultsobjectForKey:@"appVersion"]intValue];//userDefaults中的用户选择项intudUserChoose=[[userDefaultsobjectForKey:@"userOptChoose"]intValue];//userDefaults中用户的天数intudtheDays=[[userDefaultsobjectForKey:@"theDays"]intValue];//当前版本高于userDefaults中的版本号if(appVersion>udAppVersion){[userDefaultssetObject:[NSStringstringWithFormat:@"%f",appVersion]forKey:@"appVersion"];}switch(buttonIndex){case0://brutalrejectionif(udUserChoose30){[userDefaultssetObject:@"3"forKey:@"userOptChoose"];[userDefaultssetObject:[NSStringstringWithFormat:@"%d",(int)theDays]forKey:@"theDays"];}else{[userDefaultssetObject:[NSStringstringWithFormat:@"%d",(int)(theDays-udtheDays+3)]forKey:@"userOptChoose"];}休息;case1:{//表扬[userDefaultssetObject:@"1"forKey:@"userOptChoose"];[userDefaultssetObject:[NSStringstringWithFormat:@"%d",(int)theDays]forKey:@"theDays"];NSString*str=[NSStringstringWithFormat:@"https://itunes.apple.com/cn/app/id%@?mt=8",self.myAppID];[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:str]];}休息;case2:{//不好用,我要提示[userDefaultssetObject:@"2"forKey:@"userOptChoose"];[userDefaultssetObject:[NSStringstringWithFormat:@"%d",(int)theDays]forKey:@"theDays"];NSString*str=[NSStringstringWithFormat:@"https://itunes.apple.com/cn/app/id%@?mt=8",self.myAppID];[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:str]];}休息;默认值:中断;}//NSLog(@"%@",[userDefaultsobjectForKey:@"appVersion"]);//NSLog(@"%@",[userDefaultsobjectForKey:@"userOptChoose"]);//NSLog(@"%@",[你serDefaultsobjectForKey:@"theDays"]);}#endif@end具体用法如下:#import"ViewController.h"#import"LBToAppStore.h"@interfaceViewController()@end@implementationViewController-(void)viewDidLoad{[superviewDidLoad];//加载视图后进行任何其他设置,通常来自manib。}-(void)viewDidAppear:(BOOL)animated{//用户点赞系统LBToAppStore*toAppStore=[[LBToAppStorealloc]init];toAppStore.myAppID=@"1067787090";[toAppStoreshowGotoAppStore:self];}@结尾
