Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 911 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'requestReview()' was deprecated in iOS 14.0

#1
In iOS 14, Xcode is showing a warning:

> requestReview()' was deprecated in iOS 14.0

I'm using StoreKit to ask review automatically in my app.

func requestReview() {
guard shouldRequestReview else {return}
SKStoreReviewController.requestReview()
lastRequest = Date()
}

[![enter image description here][1]][1]

How to get rid of that warning?

[1]:
Reply

#2
## iOS 16+

There is now a new [RequestReviewAction](

[To see links please register here]

) that is available as an environment value:

```swift
private struct ContentView: View {
@Environment(\.requestReview) private var requestReview

var body: some View {
Button("Review") {
DispatchQueue.main.async {
requestReview()
}
}
}
}
```

## iOS 14+

### Quick solution

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

*Note: according to some comments it's more reliable with `DispatchQueue.main.async`*

### Convenient solution

Here's a true *one-liner*:
```
SKStoreReviewController.requestReviewInCurrentScene()
```

but first you need to create the following extension in `SKStoreReviewController`:
```
extension SKStoreReviewController {
public static func requestReviewInCurrentScene() {
if let scene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene {
DispatchQueue.main.async {
requestReview(in: scene)
}
}
}
}
```

<sub>Here is a [GitHub repository](

[To see links please register here]

) with different Swift extensions including [`requestReviewInCurrentScene()`](

[To see links please register here]

;

---

### Explanation

The `requestReview` function was deprecated in iOS 14:
```
@available(iOS, introduced: 10.3, deprecated: 14.0)
open class func requestReview()
```

You need to use the `requestReview(in:)` function instead:
```
@available(iOS 14.0, *)
open class func requestReview(in windowScene: UIWindowScene)
```

**Possible solutions**

- Custom extension

You can create the following extension:
```
extension UIApplication {
var currentScene: UIWindowScene? {
connectedScenes
.first { $0.activationState == .foregroundActive } as? UIWindowScene
}
}
```
and use it like this:
```
if let scene = UIApplication.shared.currentScene {
SKStoreReviewController.requestReview(in: scene)
}
```

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

- *single scene* solution (for iOS)
```
if let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
SKStoreReviewController.requestReview(in: scene)
}
```
Reply

#3
I made a small wrapper over SKStoreReviewController that saves the headache of supporting different versions of ios. Also it works for macOS.

// Review after 3 launches
AppReview.requestIf(launches: 3)

// Review after 5 days
AppReview.requestIf(days: 5)

// Review after 3 launches and 5 days
AppReview.requestIf(launches: 3, days: 5)

[To see links please register here]

Reply

#4
iOS 16 has a new way to do it:

[To see links please register here]


In my tests it is crucial to do it on the main queue. Otherwise the dialogue is unreliable.

private struct ContentView: View {

@Environment(\.requestReview) private var requestReview

var body: some View {
Button("Ask for Review") {
DispatchQueue.main.async {
requestReview()
}
}
}
}
Reply

#5
**Simple solution for iOS(13 & above) and macOS**

**iOS (Swift 5+):**

if #available(iOS 14.0, *) {
if let scene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene {
SKStoreReviewController.requestReview(in: scene)
}
} else if #available(iOS 10.3, *) {
SKStoreReviewController.requestReview()
}



**macOS:**
Don't forget to replace your Apple ID with in URL "id123456789"

guard let writeReviewURL = URL(string: "https://itunes.apple.com/app/id123456789?action=write-review") else {
print("Invalid URL")
return
}
NSWorkspace.shared.open(writeReviewURL)
Reply

#6


As `SKStoreReviewController.requestReview` is deprecated in ios14
You can use `SKStoreReviewController.requestReview(in: scene)` from ios14
Sample code is below

if #available(iOS 14.0, *) {
if let scene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene {
SKStoreReviewController.requestReview(in: scene)
}
} else if #available(iOS 10.3, *) {
SKStoreReviewController.requestReview()
}

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through