15
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SwiftでiOSアプリにレビューを促すアラートの表示

Last updated at Posted at 2015-06-22

スクリーンショット 2015-07-23 17.03.34.png

コード

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に書くとエラーが起きます。

15
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?