#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 |