引导用户添加星级评论

///弹出好评

- (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;

}


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容