LoginSignup
53
46

More than 5 years have passed since last update.

【iOS】アプリ内からレビューを依頼する 10.3未満も対応

Last updated at Posted at 2017-03-28

本日(2017/03/28)iOS 10.3が公開され、正式にSKStoreReviewControllerを使うことができるようになり、アプリ内から、レビューを直接依頼できるようになりました。

また、SKStoreReviewControllerの追加に伴って、AppStoreのレビューページを直接開くパラメータも追加されました。

こちらのパラメータはiOS 10.3未満の端末からでも開けるようなので、以前のようにユーザが操作してアプリページからレビューフォームへ移動する必要がなくなりました。

コード

ViewController.swift
import UIKit
import StoreKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()

    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        showReviewAlert()
    }

    private func showReviewAlert() {
        if #available(iOS 10.3, *) {
            // iOS 10.3以上の処理
            SKStoreReviewController.requestReview()
        } else if let url = URL(string: "itms-apps://itunes.apple.com/app/id{アプリのID}?action=write-review") {
            // iOS 10.3未満の処理
            showAlertController(url: url)
        }

    }

    private func showAlertController(url: URL) {
        let alert = UIAlertController(title: "レビューのお願い",
                                      message: "いつもありがとうございます!\nレビューをお願いします!",
                                      preferredStyle: .alert)
        self.present(alert, animated: true, completion: nil)

        let cancelAction = UIAlertAction(title: "キャンセル",
                                         style: .cancel,
                                         handler: nil)
        alert.addAction(cancelAction)

        let reviewAction = UIAlertAction(title: "レビューする",
                                         style: .default,
                                         handler: {
                                            (action:UIAlertAction!) -> Void in


                                            if #available(iOS 10.0, *) {
                                                UIApplication.shared.open(url, options: [:])
                                            }
                                            else {
                                                UIApplication.shared.openURL(url)
                                            }

        })
        alert.addAction(reviewAction)
    }
}

参考

iOS 10.3で追加されたアプリレビューを投稿できるSKStoreReviewControllerを試してみた
【Swift】AppStoreのレビューフォームを開くパラメーターが新登場 - action=write-review -

53
46
2

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
53
46