ios SKStore?Review?Controller,如何正确使用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43177249/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 09:02:25  来源:igfitidea点击:

SKStore?Review?Controller, How to use it in a correct way?

iosobjective-ciphoneios10.3skstorereviewcontroller

提问by Abhishek Mitra

I have seen some answer but not satisfied with them and got some idea, but don't know how to use it properly, so that it will execute in proper way, though i think it should be used in App delegates didFinishLaunching, but i wanted to be sure before implement it in Live app without any hustle. SKStore?Review?Controlleris only work for ios 10.3 what i read, could anybody explain with little bit of code in swift and objective c.

我已经看到了一些答案,但对它们并不满意并得到了一些想法,但不知道如何正确使用它,以便它以正确的方式执行,虽然我认为它应该在 App 委托中使用didFinishLaunching,但我想确保在 Live 应用程序中实现它之前没有任何喧嚣。 SKStore?Review?Controller仅适用于我阅读的 ios 10.3,任何人都可以用 swift 和objective c 中的一点代码解释一下。

UPDATE:

更新:

Actually I'm confused about calling the method request?Review(), Where do i need to call this method? in rootViewController's viewDidLoador in appDelegate's didFinishlaunching?

其实我对调用方法很困惑request?Review(),我需要在哪里调用这个方法?在rootViewControllerviewDidLoad还是在appDelegatedidFinishlaunching

Thanks.

谢谢。

回答by korat prashant

SKStoreReviewControlleris available in iOS 10.3 and later.

SKStoreReviewController在 iOS 10.3 及更高版本中可用。

According to APPLE's Documents:

根据苹果公司的文件:

You can ask users to rate or review your app while they're using it, without sending them to the App Store.You determine the points in the user experience at which it makes sense to call the API and the system takes care of the rest.

您可以要求用户在使用您的应用时对其进行评分或评论,而无需将他们发送到 App Store。您可以确定用户体验中调用 API 有意义的点,而系统会负责其余部分.

Inorder to display Rate/Review inside the app, you have to add StoreKitframework.

为了在应用程序内显示评分/评论,您必须添加StoreKit框架。

Please find the Sample code for both language:

请找到两种语言的示例代码:

Objective C:

目标 C:

#import <StoreKit/StoreKit.h>

- (void)DisplayReviewController {
    if([SKStoreReviewController class]){
       [SKStoreReviewController requestReview] ;
    }
}

since xCode 9 you can do:

从 xCode 9 开始,您可以执行以下操作:

#import <StoreKit/StoreKit.h>

- (void)DisplayReviewController {
    if (@available(iOS 10.3, *)) {
        [SKStoreReviewController requestReview];
    }
}

Swift:

迅速:

import StoreKit

func DisplayReviewController {
    if #available( iOS 10.3,*){
        SKStoreReviewController.requestReview()
    }
}

Update: Ask for a rating only after the user has demonstrated engagement with your app

更新:仅在用户表现出与您的应用互动后才要求评分

回答by Emre Gürses

For Objective C,

对于目标 C,

1-) Added StoreKit framework from Link Binary With Libraryenter image description here

1-) 从Link Binary With Library添加了 StoreKit 框架在此处输入图片说明

2-) Added framework

2-) 添加框架

#import <StoreKit/StoreKit.h>

3-) Added below code where you want to call App-Review pop-up. In this case, i added in viewDidLoad.

3-) 在您要调用 App-Review 弹出窗口的位置添加了以下代码。在这种情况下,我在 viewDidLoad 中添加。

  - (void)viewDidLoad {
        [super viewDidLoad];
        [SKStoreReviewController requestReview];
    }

4-) You should be aware of below explain from Apple, When you test in debug mode

4-) 当您在调试模式下测试时,您应该了解 Apple 的以下解释

When you call this method while your app is still in development mode, a rating/review request view is always displayed so that you can test the user interface and experience. However, this method has no effect when you call it in an app that you distribute using TestFlight.

当您在应用程序仍处于开发模式时调用此方法时,始终会显示评级/评论请求视图,以便您可以测试用户界面和体验。但是,当您在使用 TestFlight 分发的应用程序中调用它时,此方法无效。

回答by Shakti

I think directly calling the below is not an good idea

我认为直接调用下面的不是一个好主意

SKStoreReviewController.requestReview()

SKStoreReviewController.requestReview()

It can be done like whenever user open your app the multiple of 10(10,20,30,...100) then you can show for review

它可以像每当用户打开您的应用程序 10(10,20,30,...100) 的倍数然后您可以显示以供

so first of all you need to create an file which will be responsible for everything like saving your application open count in userdefaults ,retrieving application open count and showing requestReview() kindly have a look to the following code snippet

因此,首先您需要创建一个文件,该文件将负责将您的应用程序打开计数保存在用户默认值中、检索应用程序打开计数和显示 requestReview() 等所有事情,请查看以下代码片段

   import Foundation
   import StoreKit
   class  SpsRateManager {


private static let instance = SpsRateManager()

var shareinstance: SpsRateManager{
    return .instance
}
static func incrementAppOpenedCount() { // called from appdelegate didfinishLaunchingWithOptions:
    let userdefault = UserDefaults.standard


    let savedvalue = userdefault.integer(forKey: Configuration.APPLICATIONOPENCOUNTSTATUS)
    if savedvalue == 0 {
        print("Not saved ")
          userdefault.set(1, forKey: Configuration.APPLICATIONOPENCOUNTSTATUS)
    }
    else{
        userdefault.set(savedvalue+1, forKey: Configuration.APPLICATIONOPENCOUNTSTATUS)

    }

}

static func checkAppopencountandProvideReview(){
    let userdefault = UserDefaults.standard


    let appopencountvalue  = userdefault.integer(forKey: Configuration.APPLICATIONOPENCOUNTSTATUS)
    if appopencountvalue % 10 == 0 {
        print("its been 10 times so ask for review ")
        SpsRateManager().requestReview()
    }
    else{
        print("not enough open count dont show ")
    }

}




fileprivate func requestReview() {
    if #available(iOS 10.3, *) {
        SKStoreReviewController.requestReview()
    } else {
        // Fallback on earlier versions
        // Try any other 3rd party or manual method here.
    }
}

}

}

回答by Jordan

Adding onto korat's great answer above...

添加到上面呵叻的精彩答案中......

If your supporting a legacy Objective-C app and you want to call DisplayReviewController after a few app opens then do the following:

如果您支持旧版 Objective-C 应用程序,并且您想在打开几个应用程序后调用 DisplayReviewController,请执行以下操作:

In your class AppDelegate.m add this:

在您的类 AppDelegate.m 中添加以下内容:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  int count = [[NSUserDefaults standardUserDefaults] integerForKey:@"LaunchCount"];
  if(count < 0) count = 0;
  [[NSUserDefaults standardUserDefaults] setInteger:count+1 forKey:@"LaunchCount"];
}

//The application was in background and become active
- (void)applicationWillEnterForeground:(UIApplication *)application {
  int count = [[NSUserDefaults standardUserDefaults] integerForKey:@"LaunchCount"];
  if(count < 0) count = 0;
  [[NSUserDefaults standardUserDefaults] setInteger:count+1 forKey:@"LaunchCount"];
}

and in the controller you want to call the function:

并在控制器中调用该函数:

- (void)applicationDidBecomeActive {

  if ([[NSUserDefaults standardUserDefaults] integerForKey:@"LaunchCount"] == 5) {
     [self DisplayReviewController];
  }
}

回答by Phuc Dang

I think you may implement a method to count when they run the app and store it in UserDefaults, then call requestReview() if the count number is 5 or 10 or something like that (it depends on you), by this way you have more chance of getting a good review.

我认为您可以实现一个方法来计算他们运行应用程序并将其存储在 UserDefaults 中,然后如果计数为 5 或 10 或类似的数字(这取决于您),则调用 requestReview() ,通过这种方式您有更多获得好评的机会。