コード
ViewController.swift
let ud = NSUserDefaults.standardUserDefaults()
override func viewDidAppear(animated: Bool) {
if !ud.boolForKey("reviewed") {
let alertController = UIAlertController(
title: "おめでとうございます",
message: "クリアありがとうございました。よろしければレビューを書いて頂けませんか?今後の開発の参考に致します",
preferredStyle: .Alert)
let reviewAction = UIAlertAction(title: "レビューする", style: .Default) {
action in
let url = NSURL(string: "APP_STORE_URL")
UIApplication.sharedApplication().openURL(url!)
self.ud.setObject(true, forKey: "reviewed")
}
let yetAction = UIAlertAction(title: "まだレビューしない", style: .Default) {
action in
self.ud.setObject(false, forKey: "reviewed")
}
let neverAction = UIAlertAction(title: "今後レビューしない", style: .Cancel) {
action in
self.ud.setObject(true, forKey: "reviewed")
}
alertController.addAction(reviewAction)
alertController.addAction(yetAction)
alertController.addAction(neverAction)
presentViewController(alertController, animated: true, completion: nil)
}
}
ちょっとした解説
これをまるっとどこかのViewControllerに仕込むだけでアプリレビューを促すアラートを表示できます。
レビューする → 今後ウィンドウが表示されない + Appstoreへ飛ばす
まだレビューしない → 今後もウィンドウは出るが、一旦何もしないで閉じる。
今後レビューしない → 今後ウィンドウが表示されない。何もしないで閉じる。
※ViewDidAppearでなく、ViewDidLoadに書くとエラーが起きます。