LoginSignup
3
2

More than 5 years have passed since last update.

[iOS] Objective-CでSKStoreReviewControllerの実装

Posted at

まえふり

新 App Store 審査ガイドライン 翻訳&差分ガイド 2017年6月号の記事で、

iOS 10.3 で追加された SKStoreReviewController の使用が必須。

と書かれてあったため、おそらく今後リジェクトされると思い実装した。

実装内容

直で呼び出すとアラートは表示されないので、ワンクッション(Buttonの実装を)入れた。

- (IBAction)onButton:(id)sender {
    [self showReviewAlert:@"レビュー" reviewAlertMessage:@"お願いします。" reviewAlertAppId:@""];
}



// レビューさせるポップアップ表示
- (void)showReviewAlert: (NSString *)title reviewAlertMessage:(NSString *)message reviewAlertAppId:(NSString *) appId {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle: title
                                                                   message: message
                                                            preferredStyle: UIAlertControllerStyleAlert];

    UIAlertAction *cancelAction = [UIAlertAction  actionWithTitle: @"Cancel"
                                                            style: UIAlertActionStyleCancel
                                                          handler: nil];


    [alert addAction: cancelAction];

    UIAlertAction *reviewAction = [UIAlertAction  actionWithTitle: @"Review"
                                                            style: UIAlertActionStyleDefault
                                                          handler: ^(UIAlertAction *action) {
                                                              [self setReviewAlert: appId];
                                                          }];
    [alert addAction: reviewAction];

    // 表示
    [self presentViewController:alert animated:YES completion:nil];
}


// SKStoreReviewControllerの呼び出し
- (void)setReviewAlert: (NSString *) appId {
    // iOS 10.3以上の処理
    float iOSVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
    if (iOSVersion > 10.2f) {
        if([SKStoreReviewController class]){
            [SKStoreReviewController requestReview];
        }
    }
    else {
        if(!appId || appId.length == 0) return;

        NSString *url = [NSString stringWithFormat: @"%@%@%@", @"itms-apps://itunes.apple.com/app/id/", appId, @"?action=write-review"];
        // iOS 10以上
        if (iOSVersion > 9.9f) {
            [[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]
                                               options: @{}
                                     completionHandler: nil];
        }
        // iOS 10未満
        else {
            [[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
        }
    }
}


以下の記事を参考にさせていただきました

 
【iOS】アプリ内からレビューを依頼する 10.3にも未満も対応
 
iOS 10.3からアプリ内レーティングが可能に!- SKStoreReviewController -

3
2
0

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
3
2