---
# System prepended metadata

title: gadi-ios-agent

---

# gadi-ios-agent

## Requirements
* Xcode 10+

## Installation (**In iOS - objc**)

* Clone this repo.
* Copy the cloned folder inside the root folder of your project.
* Add the following line in your Podfile
```
pod 'gadi-ios-agent', :path => './gadi-ios-agent/'
```
**Note:** in above line `path` can be set to the location of `.podspec` file if the sdk is added locally

* Execute following commands at root project in terminal
```
1. pod repo update
2. pod install
```

## Methods


**1. initSdk( NSString apiURL, int environment )**
---
This method is initilize the SDK, without calling the method you can not use SDK functionality.

`apiURL`: NSString - endpoint specifying the route where the JSON file is stored
`environment`: int - Here we can pass environment type, like Dev, Stage, Prod, (0,1,2)

**Example**
```
#import <GadiAgentModule.h>
...
[[[GadiAgentModule alloc] init] initSdk:@"json file url" environment:"0"];
```

**2. createDigitalAddress( NSString apiEndpoint, NSDictionary userDocuments ) -> NSString**
---
This method sends an api request to `DAP` to create a digital address for the `Holder`.
This method will return response in `NSString`

`apiEndpoint`: NSString - endpoint specifying the route where the holder should request the `DAP` for creation of digital address.
`userDocument`: NSDictionary - an array of holder documents to be sent to `DAP` as a post request payload. (**NOTE** Please send the `userDocument` as an empty array i.e, `[]`)

**Example**
```
#import <GadiAgentModule.h>
...
NSString *response = [[[GadiAgentModule alloc] init] createDigitalAddress:@"https://10.10.10.10:3000/da" userDocuments:@[]];
```

**3. saveDigitalAddress(NSString digitalAddress) -> NSString**
---
This method saves the digital address generated by `DAP` agent into local database.

**Example**

```
#import <GadiAgentModule.h>
...
NSString *response = [[[GadiAgentModule alloc] init] saveDigitalAddress:@"did:gadi:bba04f6985f560446c122d235ed2e51bf7c10864"];
```


**4. getDigitalAddress() -> NSString**
---
This method returns the digital address generated by DAP and saved in local database by createDigitalAddress method.

**Example**

```
#import <GadiAgentModule.h>
...
NSString *results = [[[GadiAgentModule alloc] init] getDigitalAddress];
```

**5. getAgentUrl() -> NSString**
---
This method returns the mediator agent url discovered from DAP and saved in local database.

**Example**

```
#import <GadiAgentModule.h>
...
NSString *results = [[[GadiAgentModule alloc] init] getMediatorAgentUrl];
```

**6. registerDAP(NSString label, NSString digitalAddress) -> NSString**
---
This method registers holder's digital address on mediator agent.

**Example**

```
#import <GadiAgentModule.h>
...
NSString *receive = [[[GadiAgentModule alloc] init] registerWithMediatorAgent:@"ANY RANDOM NAME" digitalAddress:@"DIGI ADDRESS RECEIVED FROM getDigitalAddress"];
```

**7. storeCredentials(NSDictionary credDetails, NSString credTag) -> NSString**
---
This method stores all the credentials which are issued or self attested.

**Example**

```
#import <GadiAgentModule.h>
...
NSString *storeResponse = [[[GadiAgentModule alloc] init] storeCredentials:@{@"name": @"john"} credentialsTag:@"SELF_ATTESTED"];
```


**8. getCredentials() -> NSArray**
---
This method returns all the credentials saved locally.

**Example**

```
#import <GadiAgentModule.h>
...
NSArray *getCreds = [[[GadiAgentModule alloc] init] getCredentials];
```

**9. saveFcmToken() -> NSString**
---
This method saves the generated FCM token to local db.

**Example**

```
#import <GadiAgentModule.h>
...
NSString *saveFCMToken = [[[GadiAgentModule alloc] init] saveFcmToken:@"YOUR_FCM_TOKEN"];
```

**10. getFcmToken() -> NSString**
---
This method returns the generated FCM token from local db.

**Example**

```
#import <GadiAgentModule.h>
...
NSString *getFCMToken = [[[GadiAgentModule alloc] init] getFcmToken];
```


**11. getCredentialDetailsFromRecordID((NSString recordId, NSString digitalAddress, NSString endPointUrl)) -> NSDictionary**
---
recordId: NSString - recordId will be received in a payload of notification.

digitalAddress: NSString- digitalAddress will be received in a response of decodeQRcode() method.

endPointUrl: NSString - endPointUrl will be received in a payload of notification.

This method request to API to receive a credential detail. And this will be executed when the holder receives a notification of type as CREDENTIAL_ISSUED in notification payload.

**Example**

```
#import <GadiAgentModule.h>
...
NSDictionary *result = [[[GadiAgentModule alloc] init] getCredentialDetailsFromRecordID(recordId: "RECORD ID", digitalAddress: "DIGITAL ADDRESS", endPointUrl: "ENDPOINT URL")];
```

**12. acceptConnectionInvitation(NSString digitalAddress, NSString invitationLink, NSString spOrg, int allowDuplicate ) -> NSDictionary**
---
invitationLink: String- invitationLink: String- invitationLink will be received after scan a QR code.digitalAddress: String- digitalAddress will be received in a response of decodeQRcode() method/you can get from getDigitalAddress() method of sdk.

allowDuplicate:int - allowDuplicate will be received after scan a QR code
spOrg : String -  spOrg will be received after scan a QR code

This method accepts a connection invitation by using the Shared Agent API. And same time store connection in local DB using storeConnection() method.

Example
```
#import <GadiAgentModule.h>
…
NSDictionary *acceptInvitationResponse = [[GadiAgentModule alloc] init] acceptConnectionInvitation:@“Invitation Link”,@“Digital Address”,@"spOrg",@"allowDuplicate value in int"];
```

**13. storeConnection(NSDictionary *connection)-> NSString**
---
This method stores details of connection in local DB.

**Example**
```
#import <GadiAgentModule.h>

NSString *storeResponse = [[[GadiAgentModule alloc] init] storeConnection:@"connection dictionary"];
```

**14. getConnections() -> NSArray**
---
This method returns a list of connections stored in local DB.

**Example**
```
#import <GadiAgentModule.h>
...
NSArray *getConnections = [[GadiAgentModule alloc] init] getConnections];
```

**15. sendConsentForCredentialRequest(NSString endPointUrl, NSString recordId, NSString digitalAddress, Bool isAcceptConsent) -> NSDictionary**
---
endPointUrl: NSString - endPointUrl specifying Shared Agent API, which will be receiving in a payload of notification as CONSENT_ENDPOINT .
recordId: NSString - recordId will be receiving in a payload of notification.
digitalAddress: NSString- digitalAddress will be receiving in a response of decodeQRcode() method.
isAcceptConsent: Bool - boolean specifying an accept/decline consent. true/false

This method sends consent to Shared Agent for issued Credential for the Holder.
This method will return response in NSDictionary.

**Example**
```
#import <GadiAgentModule.h>
...
NSDictionary *acceptInvitationResponse = [[GadiAgentModule alloc] init] sendConsentForCredentialRequest:@"End Point Url",@"RecodId",@"Digital Address",@"true/false"];
```

**16. sendConsentForProofRequest(NSString proofRecordId, NSString digitalAddress, NSString endPointUrl) -> NSDictionary**
---
endPointUrl: NSString - endPointUrl specifying Shared Agent API, which will be receiving in a payload of notification as PROOF_REQUEST .recordId: NSString - recordId will be receiving in a payload of notification.digitalAddress: NSString- digitalAddress will be receiving in a response of decodeQRcode() method.

This method sends consent to Shared Agent for proof request.This method will return response in NSDictionary.

**Example**
```
#import <GadiAgentModule.h>
...
NSDictionary *response = [[GadiAgentModule alloc] init] sendConsentForProofRequest:@"Proof Record ID",@"Digital Address",@"End Point Url"];
```

**16. deleteConnection(NSString connectionId, NSString digitalAddress) -> NSString**
---
NSString - connectionId , Need to pass connectionId to delete the specific connection record.
NSString - digitalAddress will be receiving in a digital address from getDigitalAddress()

Note: could not delete defult connection.

**Example**

```
#import <GadiAgentModule.h>
...
NSString *response = [[GadiAgentModule alloc] init] deleteConnection:@"connection ID",@"Digital Address"];
```
**17. decodeQRcode(NSString encodedString) -> NSDictionary**
---
This method returns the decoded value of QR code.

**Example**

```
#import <GadiAgentModule.h>
#import <Realm/Realm.h>
...
NSDictionary *getDecodedValue = [[[GadiAgentModule alloc] init] decodeQRcode:@"ENCODED STRING"];
```

**17. registerToken -> NSDictionary**
---
This method registers a FCM token by using the Shared Agent API. This will help to receive a notification for issue credential, proof verification and etc.

(NOTE Before executing this method, digital address and fcm token must be saved using saveDigitalAddress() and saveFcmToken() method respectively. )

**Example**

```
#import <GadiAgentModule.h>
...
NSString *response = [[GadiAgentModule alloc] init] registerToken];
```

**19. getConnectionInvitation(NSString endPointUrl, NSString recordID, NSString digitalAddress, NSString spOrg, NSNumber consent, int allowDuplicate) -> NSDictionary**
---
endPointUrl: String - endPointUrl specifying Shared Agent API, which will be receiving in a payload of notification as CONNECTION_REQUEST .
recordId: String - recordId will be receiving in a payload of notification.
digitalAddress: String- digitalAddress will be receiving in a response of decodeQRcode() or getDigitalAddress() method.
spOrg: String - orgName is organization name.  It will be receiving in a payload of notification.
consent: int - int specifying an accept/decline consent. Here, 1 for accept a consent and 0 for decline a consent.
allowDuplicate: int- allowDuplicate will be received. Here, 1 for allow duplicate and 0 for not allow duplicate .
(NOTE Please set a default 1 for allowDuplicate )

This method will be called once receive a notification of  notification type CONNECTION_REQUEST. This method accepts a connection invitation by using the Shared Agent API. And same time store connection in local DB using storeConnection() method.

**Example**

```
#import <GadiAgentModule.h>
...
 NSDictionary *response =  [[GadiAgentModule alloc] init] getConnectionInvitation:@"API URL" recordId:@"RECORD ID" digitalAddress:@"DIGITAL ADDRESS" spOrg:@"ORG NAME" consent:[NSNumber numberWithInt:1] allowDuplicate:1];
```