10
8

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 3 years have passed since last update.

【Swift】アプリのレビューアラートを出す方法

10
Posted at

はじめに

個人開発でアプリのレビューアラートを出す実装をしたので、忘れないようにメモ的に残しておきます。

この記事でわかること

  • 画像のアラートを表示方法
    IMG_C0ABD90E4DDC-1.jpeg

アラートを出すコード

コードはものすごく簡単です。
まずはアラートを表示させる処理を書くファイルにimport StoreKitをしましょう。
そして、アラートを出したいタイミングで以下のコードを書けば終わりです。

     if let scene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene {
         SKStoreReviewController.requestReview(in: scene)
     }

おまけ

今回個人開発では、特定のアクションを規定回数行なったときにアラートを表示するようにしました。
アラートの表示を管理するために以下のようなクラスを作ったので参考になるかは分かりませんが共有しておきます。

import Foundation

final class ExecuteCounterForReviewAlert {

    private let executeCountKey = "executeCount"
    private var executeCount: Int {
        didSet {
            UserDefaults.standard.set(executeCount, forKey: executeCountKey)
        }
    }

    func incrementExecuteCount() {
        executeCount += 1
    }

    func isShowReviewAlert() -> Bool {
        return executeCount == 5 || executeCount == 10
    }

    init() {
        executeCount = UserDefaults.standard.integer(forKey: executeCountKey)
    }
}

1度レビューしたことがあってもアラートが出るのか?

今回レビューアラートは特定のアクションを5回、10回行なったときに表示するようにしました。
開発中にはアラートは表示できても、評価は送信できません。
そこで疑問に思ったのが以下2点です。

  • 5回目のアクションを行った際にアラートを表示し、レビューを送信したら10回目もアラートが出てしまうのか?
  • ストアから以前レビューしていてもアラートが出てしまうのか?

結論から言うと、たぶん出ないと思われます。

appleのドキュメントにはそれらしき記述は見られませんでした。

appleのドキュメントからは見つけられなかったのでChatGPTさんに聞いてみたら、出ないと教えてくれました。
スクリーンショット 2023-03-06 21.32.34.png

おわりに

最後はChatGPT頼りになってしまいました。また本当のことがわかったら追記するかもです。
もしご存じの方がいたら教えてください🙇
個人開発アプリがいい感じに売れるように頑張りたい。

10
8
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
10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?