SDK Guide
...
For Mobile Apps/Games
Unity

Unity (iOS)

20min

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.

Document image


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.

Document image


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.

Document image


Make sure you have enabled XCode Project with a valid developer profile & signing certificates and valid Application Bundle Id.

Document image


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.

Document image


Select a valid provision profile and a valid signing certificate.

Document image


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.

Document image


Select a downloaded Enefits package and choose 'Open'. Make sure all components are selected from the package and then click on 'Import'.

Document image


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

C#


<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:



C#


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.

C#


where completionHandler can be defined as:

C#


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:

C#


walletcompletionHandler can be defined as:

C#


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.

C#


completionHandler can be defined as:

C#


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:

C#


To Check if Enefits SDK was able to connect to a blockchain account.

C#


Get the address of the connected account.

C#


where getConnectAccountcompletionHandler can be defined as:

C#


account => Connected account information.

blockChainInfo => Wallet information (JSON string)

Get the blockchain info for the connected account.

C#


where getChainDatacompletionHandler can be defined as:

C#


data => blockchain info for the connected account (JSON string).

Disconnect from the blockchain account.

C#


where completionHandler can be defined as:

C#


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.