SDK Guide
...
For Mobile Apps/Games
Unity
Unity (iOS)
20 min
this guide is for anyone who wishes to integrate the enefits unity sdk for ios into the unity project we highly recommend reviewing the general usage guide to familiarise yourself with general sdk workflow concepts before continuing you will need to generate an api key with your enefits account before continuing with integration to obtain an api key, simply register at https //x enefits co/ , and go to developer in the account menu in the top right section from there, generate an api key and save this for sdk initialization we only show this once, so if you lose this api key, you’ll have to re generate it from the developer section run the demo to run a live demo, download enefitssdkdemoapp open it with unity and provide your own api key where requested also, note that enefitssdkdemoapp requires an ios device to work it will not work in the unity editor or the ios simulator make sure you have ios build options support available in unity also, make sure you have xcode or xcode command line tools installed go to unity > file > build settings make sure 'ios' option is selected select option 'build', it will ask for a location where unity will generate ios project select a location, then it will generate ios project at a specified location open generated xcode project file with xcode make sure you have enabled xcode project with a valid developer profile & signing certificates and valid application bundle id change bundle identifier, version and build number as per your requirement you can either run enefitssdkdemoapp on the device or create a generic device build select a valid provision profile and a valid signing certificate download enefits sdk unity package the enefitssdk unity ios package can be downloaded from this link import enefits sdk unity package select project layout go to the assets folder right click and select import package > custom package select a downloaded enefits package and choose 'open' make sure all components are selected from the package and then click on 'import' sdk setup please make sure to call any sdk method inside 'unity ios && !unity editor' block, as it is only available for ios \#if unity ios && !unity editor // call sdk method here \#endif initialize the sdk \#if unity ios && !unity editor enefitsnative enefitssdk initializesdk("\<app name>","\<api key>",completionhandler); \#endif \<app name> string type describes your unity ios application name \<api key> string type api key provided to you during the registration at https //x enefits co/ completionhandler can be defined as \[monopinvokecallback ( typeof ( action\<bool,string> ) )] public static void completionhandler ( bool status, string message ) { } status => true/false sdk init success/failed message => error / message from the enefits sdk connect wallet display a button or call to action (for example 'connect wallet') which when tapped will prompt the user to connect a wallet after the user selects a wallet and initiates a session, the returned address will be available to the enefits sdk to check nfts and any offers the user is eligible for this function will open a view with a list of supported providers enefits sdk fires the callback after successfully connecting with a blockchain account \#if unity ios && !unity editor enefitsnative enefitssdk present(completionhandler); \#endif where completionhandler can be defined as \[monopinvokecallback ( typeof ( action\<bool,string> ) )] public static void completionhandler ( bool status, string message ) { } status = true => connecting with wallet status = false => already connected or not initialized message => string message from the enefits sdk to get callback after wallet connect \#if unity ios && !unity editor enefitsnative enefits isconnectedwithwallet(walletcompletionhandler); \#endif walletcompletionhandler can be defined as \[monopinvokecallback ( typeof ( action\<bool> ) )] public static void walletcompletionhandler ( bool status ) { } status = true => conected with wallet successfully status = false => failed to connect wallet get all enefits offers this method returns all offers that the user is eligible for based on the address they provided when they connected their wallet \#if unity ios && !unity editor enefitsnative enefitssdk getoffers(completionhandler); \#endif completionhandler can be defined as \[monopinvokecallback ( typeof ( action\<bool,string> ) )] public static void completionhandler ( bool status, string message ) { } status = true => able to fetch offers successfully status = false => failed to get offers message => if status = true then message describes offers list (json string), if status = false, then message describes error info helper functions use the functions provided below to create tighter integration with the enefits sdk and manage user connectivity states to check if sdk init success or failed \#if unity ios && !unity editor if(enefitsnative enefits isinitcomplete()) { // sdk init success } else { // sdk init failed } \#endif to check if enefits sdk was able to connect to a blockchain account \#if unity ios && !unity editor if(enefitsnative enefits isaccountconnected()) { // wallet account connected } else { // failed to connect wallet account } \#endif get the address of the connected account \#if unity ios && !unity editor enefitsnative enefits getconnectaccount(getconnectaccountcompletionhandler); \#endif where getconnectaccountcompletionhandler can be defined as \[monopinvokecallback ( typeof ( action\<string> ) )] public static void getconnectaccountcompletionhandler ( string account, string blockchaininfo ) { } account => connected account information blockchaininfo => wallet information (json string) get the blockchain info for the connected account \#if unity ios && !unity editor enefitsnative enefits getchaindata(getchaindatacompletionhandler); \#endif where getchaindatacompletionhandler can be defined as \[monopinvokecallback ( typeof ( action\<string> ) )] public static void getchaindatacompletionhandler ( string data ) { } data => blockchain info for the connected account (json string) disconnect from the blockchain account \#if unity ios && !unity editor enefitsnative enefits disconnect(completionhandler); \#endif where completionhandler can be defined as \[monopinvokecallback ( typeof ( action\<bool,string> ) )] public static void completionhandler ( bool status, string message ) { } status = true/fase => able to disconnect from wallet successfully / failed to disconnect from wallet message => if status = false then message explains reason for failure while disconnecting