Unity 调用IOS的StoreKit实现在游戏内部的对游戏进行星级评价和评论

 

 

在Unity目录下 新建一个文件夹  Plugins\IOS

 

 

IOS文件夹下 新建两个文件  UnityStoreKit.m, UnityStoreKit.h


UnityStoreKit.m:

 


#import "UnityStoreKit.h"


@implementation UnityStoreKit

#if defined(__cplusplus)

extern "C"{
    
#endif
    
    void _goComment()
    
    {
        
        if([SKStoreReviewController respondsToSelector:@selector(requestReview)]) {// iOS 10.3 以上支持
            
            [SKStoreReviewController requestReview];
            
        } else { // iOS 10.3 之前的使用这个
            
            NSString *appId = @"1488291408"; //项目在苹果后台的appid
            
            NSString  * nsStringToOpen = [NSString  stringWithFormat: @"itms-apps://itunes.apple.com/app/id%@?action=write-review",appId];//替换为对应的APPID
            
            //[[UIApplication sharedApplication] openURL:[NSURL URLWithString:nsStringToOpen]];
			//好像这句快一点
			dispatch_async(dispatch_get_main_queue(), ^{
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:nsStringToOpen] options:@{} completionHandler:nil];
            });
            
        }
        
    }
    
#if defined(__cplusplus)
    
}

#endif



@end

UnityStoreKit.h:

//
//  GJCSocialShare.h
//  test
//
//  Created by wu qing on 2018/7/10.
//  Copyright © 2018年 hg. All rights reserved.
//

//

//  UnityStoreKit.h

//  test

//

//  Created by HH on 2018/4/13.

//  Copyright © 2018年 HH. All rights reserved.

//



#import <Foundation/Foundation.h>

#import <StoreKit/StoreKit.h>



@interface UnityStoreKit : NSObject



@end



 

声明:

//先声明
#if UNITY_IOS
    [System.Runtime.InteropServices.DllImport("__Internal")]
    static extern void _goComment();
#endif

 

在需要弹出 五星好评的地方 调用:

//再调用
#if UNITY_IOS
        _goComment();
#endif

 

Guess you like

Origin blog.csdn.net/qq_39162566/article/details/113112442