///弹出好评
- (void)haoping {
// if([SKStoreReviewController respondsToSelector:@selector(requestReview)]){
// [SKStoreReviewController requestReview];
// }else{
if (![self startFifteen]) {//非启动十五次
return;
}
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"提示"
message:@"给个五星好评吧亲! "
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *feedbackAction = [UIAlertAction actionWithTitle:@"我要吐槽o(╯□╰)o" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
SuggestMessageViewController * vc = [[SuggestMessageViewController alloc]init];
[self.navigationController pushViewController:vc animated:YES];
}];
[alert addAction:feedbackAction];
NSString *cancelStr = @"看看再说!(>_<)";
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelStr style:UIAlertActionStyleDefault handler:nil];
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"五星好评(^_^)" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
NSString *nsStringToOpen = [NSString stringWithFormat: @"itms-apps://itunes.apple.com/app/id%@?action=write-review",@"1040758040"];//替换为对应的APPID
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:nsStringToOpen]];
}];
[alert addAction:cancelAction];
[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];
// }
}
#pragma mark - 启动次数是否满足好评条件
- (Boolean)startFifteen {
//根据版本号判断是否第15次启动,弹出好评
NSUserDefaults* defaulut = [NSUserDefaults standardUserDefaults];
// 从沙盒中读取上一次存储的手机版本号
NSInteger num = [defaulut integerForKey:@"HAOPING"];
NSString* lastVersion = [defaulut objectForKey:@"appVersion"];
NSLog(@"num = %zd", num);
// 获取当前的手机应用版本号
NSDictionary* dict = [NSBundle mainBundle].infoDictionary;
NSString* appVersion = dict[@"CFBundleShortVersionString"];
[defaulut setInteger:num+1 forKey:@"HAOPING"];//存储次数
[defaulut setObject:appVersion forKey:@"appVersion"];//存储手机应用版本
[defaulut synchronize];
if (![lastVersion isEqualToString:appVersion]) {//版本号不一致时 重置次数
[defaulut setInteger:1 forKey:@"HAOPING"];//存储次数
}
//判断版本号,且启动过15次
if ([lastVersion isEqualToString:appVersion] && num == 15) {
return true;
}
return false;
}


网友评论