SDK Guide
For Mobile Apps/Games
iOS
9 min
this guide is for anyone who wishes to integrate the enefits mobile sdk into an ios native app before continuing, we highly recommend reviewing the general usage guide to familiarize 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 http //enefits co http //enefits co , go to developer in the account menu in the top right section from there, generate an api key and save this for all api requests as defined below we only show this once so if you lose this api key, you’ll have to re generate from the developer section run the demo to run a live demo, visit https //bajaar beanstalkapp com/enefits mobile sdk/browse/git/ios https //bajaar beanstalkapp com/enefits mobile sdk/browse/git/ios and provide your own api key where requested download the sdk the enefits ios sdk can be downloaded from https //bajaar beanstalkapp com/enefits mobile sdk/browse/git/ios https //bajaar beanstalkapp com/enefits mobile sdk/browse/git/ios installation add the enefitssdk xcframework to your project go to targets > general > frameworks change the embed to embed & sign sdk setup initialize the sdk import the sdk in the required controllers > "import enefitssdk" enefits shared initializesdk(name your app name here, apikey your api key here) { flag, message in / flag > bool true > success false > failed / / message > string (from the enefits sdk) / } connect wallet display a button or call to action (for example connect wallet) which when pressed or clicked 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 will fire the callback after successfully connecting with a blockchain account enefits shared present(from viewcontroller, apikeystring your api key here, completionhandler { flag, message in if flag == false{ / already connected or not initialized, show the message from enefits sdk / }else{ / connecting with wallet / } }) / get callback after wallet connected / enefits shared isconnectedwithwallet = { flag in if flag == true { / conected with wallet success / if let session = enefits shared walletconnect? session{ guard let walletstring = session walletinfo? accounts first else { return } } }else{ / failed to connect with wallets / } } get all enefits offers this method will return all offers that the user is eligible for based on the address they provided when they connected their wallet based on the response from this method and the existence of a specific id value that the mobile app is looking for, your app logic will handle accordingly enefits shared getoffers(apikeystring \ your api key here, completionhandler { flag, message in if flag == false { / failed to get offers, show the message from enefits sdk / }else{ / got the offers list in the message / } }) helper functions use the functions provided below to create a tighter integration with the enefits sdk and manage user connectivity states / check if enefits sdk has successfully initialised @return boolean / let isinitcomplete = enefits shared isinitcomplete / check if enefits sdk was able to connect to a blockchain account @return boolean / let isaccountconnected = enefits shared isaccountconnected / get the address of the connected account @return \[string any], string / enefits shared getconnectaccount(apikeystring \ your api key here, completionhandler { account, blockchaininfo in / account > string returns the connected account / / blockchaininfo > \[string any] returns the walletinformations / }) / get the blockchain info for the connected account @return string / enefits shared getchaindata(apikeystring \ apikeyvalue, completionhandler { blockchaininfo in }) / disconnect from the blockchain account / enefits shared disconnect(apikeystring \ your api key here, completionhandler { flag, message in if flag == true { / disconnected / }else{ / no session found show the error message from sdk / } })