Skip to content

Commit

Permalink
add thread safe for in-app review & update README
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinya committed Oct 29, 2021
1 parent b95fa0f commit 8a7bcad
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ iOS 9.0+, Swift 5.5

## Installation

##### Swift Package Manager (Recommended)
#### Swift Package Manager (Recommended)

- File > Swift Packages > Add Package Dependency
- Add `https://github.com/Jinya/AppStoreReviewManager.git`
- Select "Exact Version"
- Select "Exact Version" (recommend using the latest exact version)


## How to Use
Expand All @@ -23,7 +23,7 @@ iOS 9.0+, Swift 5.5
import AppStoreReviewManager

// Get App Store page url String for your app
AppStoreReviewManager.appStorePageURLString(with: YOUR_APP_APP_STORE_ID)
let urlString = AppStoreReviewManager.appStorePageURLString(with: YOUR_APP_APP_STORE_ID)

// Open App Store page for your app
AppStoreReviewManager.openAppStorePage(with: YOUR_APP_APP_STORE_ID)
Expand Down
33 changes: 21 additions & 12 deletions Sources/AppStoreReviewManager/AppStoreReviewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,32 @@ public struct AppStoreReviewManager {

/// 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 period.
public static func requestReviewInApp() {
if #available(iOS 14.0, *) {
let keyWindow = UIApplication.shared.connectedScenes.compactMap({ $0 as? UIWindowScene }).flatMap { $0.windows }.first { $0.isKeyWindow }
guard let windowScene = keyWindow?.windowScene else {
assertionFailure("AppStoreReviewManager can't find key window of the app!")
return
let task = {
if #available(iOS 14.0, *) {
let keyWindow = UIApplication.shared.connectedScenes.compactMap({ $0 as? UIWindowScene }).flatMap { $0.windows }.first { $0.isKeyWindow }
guard let windowScene = keyWindow?.windowScene else {
assertionFailure("AppStoreReviewManager can't find key window of the app!")
return
}
SKStoreReviewController.requestReview(in: windowScene)
} else if #available(iOS 10.3, *) {
SKStoreReviewController.requestReview()
} else {
#if DEBUG
print("This operation is not supported on systems older than iOS 10.3")
#endif
}
SKStoreReviewController.requestReview(in: windowScene)
} else if #available(iOS 10.3, *) {
SKStoreReviewController.requestReview()
}

if Thread.isMainThread {
task()
} else {
#if DEBUG
print("This operation is not supported on systems older than iOS 10.3")
#endif
DispatchQueue.main.async {
task()
}
}
}


/// To enable a user to initiate a review as a result of an action in the UI use a deep link to the App Store page for your app with the query parameter action=write-review appended to the URL.
/// - Parameter id: the App Store ID for your app, you can find the App Store ID in your app's product URL
public static func requestReviewInAppStore(with id: String) {
Expand Down

0 comments on commit 8a7bcad

Please sign in to comment.