11//
2- // AppStoreReviewManager
3- // https://github.com/Jinya/AppStoreReviewManager
2+ // AppStoreReviewManager
3+ // The MIT License (MIT)
44//
5- // Created by Jinya on 2021/10/29.
6- //
7- // Copyright (c) 2021 Jinya<https://github.com/Jinya>
8- //
9- // Permission is hereby granted, free of charge, to any person obtaining a copy
10- // of this software and associated documentation files (the "Software"), to deal
11- // in the Software without restriction, including without limitation the rights
12- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13- // copies of the Software, and to permit persons to whom the Software is
14- // furnished to do so, subject to the following conditions:
15- //
16- // The above copyright notice and this permission notice shall be included in
17- // all copies or substantial portions of the Software.
18- //
19- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25- // THE SOFTWARE.
5+ // Copyright (c) 2021-2022 Jinya (https://github.com/Jinya)
266
277import UIKit
288import StoreKit
299
3010@available ( iOS 9 . 0 , * )
3111public struct AppStoreReviewManager {
32-
33- private static let baseURLString = " https://apps.apple.com/app "
34-
35- /// Get the App Store page url string for your app.
36- /// - Parameter id: the App Store ID for your app, you can find the App Store ID in your app's product URL
37- /// - Returns: the App Store page url string for your app
38- public static func appStorePageURLString( with id: String ) -> String {
39- return baseURLString + " /id \( id) "
12+ /// Base URL string
13+ private static let base = " https://apps.apple.com/app "
14+
15+ /// Get the App Store product page URL string with a given App Store ID.
16+ private static func productURLString( with appStoreID: String ) -> String {
17+ return base + " /id \( appStoreID) "
18+ }
19+
20+ /// Get the App Store product page URL with a given App Store ID.
21+ /// - Parameter appStoreID: The App Store ID of a product.
22+ /// - Returns: A product URL to the App Store.
23+ public static func productURL( with appStoreID: String ) -> URL ? {
24+ return URL ( string: productURLString ( with: appStoreID) )
4025 }
4126
42- /// Request StoreKit to ask the user to rate or review your app, users will submit a rating through the standardized prompt, and can write and submit a review without leaving the app. You can prompt for ratings up to three times in a 365-day.
27+ /// Tells StoreKit to ask the user to rate or review your app, if appropriate.
28+ ///
29+ /// This is a convenient wrapper method for `SKStoreReviewController.requestReview()` and `SKStoreReviewController.requestReview(in: UIWindowScene)`.
4330 @available ( iOS 10 . 3 , * )
44- public static func requestReviewInApp ( ) {
31+ public static func requestReview ( ) {
4532 let block = {
4633 if #available( iOS 14 . 0 , * ) {
4734 guard let windowScene = UIApplication . shared. connectedScenes
4835 . first ( where: { $0. activationState == . foregroundActive } ) as? UIWindowScene
4936 else {
50- debugPrint ( " AppStoreReviewManager couldn't find a foreground active window scene to request review alert! " )
37+ Swift . print ( " AppStoreReviewManager couldn't find a foreground active window scene to request review alert! " )
5138 return
5239 }
5340 SKStoreReviewController . requestReview ( in: windowScene)
@@ -65,10 +52,10 @@ public struct AppStoreReviewManager {
6552 }
6653 }
6754
68- /// Initiate a write review form for a deep link to the App Store page for your app .
69- /// - Parameter id: the App Store ID for your app, you can find the App Store ID in your app's product URL
70- public static func requestReviewInAppStore ( with id : String ) {
71- let urlString = appStorePageURLString ( with: id ) + " ?action=write-review "
55+ /// Automatically open the App Store product page and present a write review form in the App Store .
56+ /// - Parameter appStoreID: The App Store ID of a product.
57+ public static func openProductPageForReview ( with appStoreID : String ) {
58+ let urlString = productURLString ( with: appStoreID ) + " ?action=write-review "
7259 guard let writeReviewURL = URL ( string: urlString) else {
7360 assertionFailure ( " Expected a valid URL, \( urlString) is not a valid url string. " )
7461 return
@@ -79,20 +66,4 @@ public struct AppStoreReviewManager {
7966 UIApplication . shared. openURL ( writeReviewURL)
8067 }
8168 }
82-
83- /// Open a deep link to the App Store page for your app.
84- /// - Parameter id: the App Store ID for your app, you can find the App Store ID in your app's product URL
85- public static func openAppStorePage( with id: String ) {
86- let urlString = appStorePageURLString ( with: id)
87- guard let appStorePageURL = URL ( string: urlString) else {
88- assertionFailure ( " Expected a valid URL, \( urlString) is not a valid url string. " )
89- return
90- }
91- if #available( iOS 10 . 0 , * ) {
92- UIApplication . shared. open ( appStorePageURL, options: [ : ] , completionHandler: nil )
93- } else {
94- UIApplication . shared. openURL ( appStorePageURL)
95- }
96- }
97-
9869}
0 commit comments