Nonsense not much to say directly on the code.
The OC Code of a Xcode side
Create an empty project in Xcode (don't engage Baidu), then build a. h and. m file, and remember to change the suffix of. m to. mm (. mm files and. m files) except that. mm files can contain objective-c and C code, can also contain C + + code ), this class inherits from NSObject
The. h code is as follows:
unitystorekit.h// unitystorekit//// Created by Mac on 2017/12/14.// Copyright? 2017 Mac. All rights reserved.//#import <Foundation/Foundation.h> #import <StoreKit/StoreKit.h> @interface Unitystorekit:nsobject@end
The. mm code is as follows:
////unitystorekit.m//unitystorekit////Created by Mac on 2017/12/14.//Copyri Ght? 2017 Mac. All rights reserved.//#import "UnityStoreKit.h" @implementation unitystorekit#if defined (__cplusplus) extern "C" {# endif void _gocomment () {if ([Skstorereviewcontroller respondstoselector: @selector (Requestreview)]) {//IOS 1 More than 0.3 support [Skstorereviewcontroller Requestreview]; } else {//IOS 10.3 before using this nsstring *appid = @ "1280215473"; NSString * Nsstringtoopen = [NSString stringWithFormat: @ "Itms-apps://itunes.apple.com/app/id%@?action=write-review" , the appid];//is replaced by the corresponding appId [[uiapplication sharedapplication] Openurl:[nsurl Urlwithstring:nsstringtoopen]]; }} #if defined (__cplusplus)} #endif @end
The star rating within the software is a new feature after IOS10.3. We export these two files to the Plugins folder in unity. The storekit that the two files depend on is checked in unity (the library is automatically referenced when unity is packaged into a Xcode file) and the platform is selected as the iOS platform (this is packaged as an iOS package for both files). As shown in the following:
The calling code inside the two untiy
Using unityengine;using system.collections;using system.runtime.interopservices;public class UnityStoreKitMgr: Monobehaviour {private static unitystorekitmgr _instance;public static Unitystorekitmgr instance{get{if (_instance== NULL) {Gameobject go= new Gameobject ("Unitystorekitmgr"); _instance=go. Addcomponent<unitystorekitmgr> ();D ontdestroyonload (GO); return _instance;}} [DllImport ("__internal")]private static extern void _gocomment ();p ublic void Gotocommnet () {#if unity_iphone _gocomment (); #endif}}
[DllImport ("__internal")]
I'm not quite sure about that either. Anyway is the extension that kind of seemingly is called the DL some functions (must write).
_gocomment () must be the same as the function inside the. mm file.
Three iOS callback untiy
There is only one way:
Unitysendmessage ("Unitystorekitmgr", "OnCancel", "params");
First argument: Game object bound by the script that invokes the Unity function
Second argument: Calling the Unity function name
Third parameter: Call the Unity function parameter (only string type, same as Android)
Unity calls iOS Storekit for star ratings and reviews of games inside the game