Favcy iOS SDK (v1.9): Developer Guide

Objective

The objective of this developer guide is to help iOS Developers to integrate with the Favcy Ecosystem, using the Favcy iOS SDK.

Prerequisites

It is assumed, that the audience of this document has a good understanding of the iOS Development Environment. All the examples in this document are explained using Xcode as the IDE. The developers are required to use Xcode as the development IDE.

The tools required to access iOS Favcy SDK are Xcode and Facebook SDK. Since most applications are already using their own version of the Facebook SDK it is therefore not integrated as a part of the Favcy SDK.

The Favcy SDK is tested against Facebook SDK 4.11.0 and should stay compatible with the later versions as well.

Installation

Step 1. 

  • Uncompress the zip file that contains the Favcy SDK.

Step 2.

  • Drag and drop the framework into your Xcode Demo project. Do not forget to check “Check Copy items if needed” option.
  • Ensure that the Favcy.framework is available in the “Linked Frameworks and Libraries” in the General tab of the Demo project.

Step 3.

  • Add the Favcy.framework into the “Embedded Binaries” in the General tab of the Demo project.

Step 4.

  • Now go to the “Build Settings” tab of the Demo project. Here, find the “Search Paths” section and edit two subcategories :
  1. Framework Search Paths
  2. Library Search Paths

Add the path of the Facebook SDK(where Facebook SDK is downloaded) here in both of these subcategories.

Remember, the Facebook SDK must neither be placed in the project folder nor it must be added in the project(By Adding files or drag and drop). The other general settings to attach Facebook SDK are to be done as defined by Facebook.

Step 5.

  • Now, the Favcy framework can be imported into your application.

Helper Classes

In order to use the Favcy SDK, the following Helper Classes need to be understood.

Class FavcyError.h

The object of this class is returned with the Error Message and Error Code.

Class FavcyProfile.h

This class is the storage class for all the parameters, that are required by the application. The FavcyProfile will be returned with the associated parameters on successful user logIn.

The various methods to fetch profile information from FavcyProfile are

-(NSString *)getEmail;

Returns the Email ID of the User.

-(NSString *)getCurrencyValue;

Returns the Total Points the user has corresponding to thebrand.

-(NSString *)getBrandName;

Returns the group name the user is a part of.

-(NSString *)getBrandImg;

Returns the URL for the brand image, as configured in the Favcy Eco System

-(NSString *)getFavcyUserToken;

Returns the user token associated with Favcy and is specific to the group the user is part of.

-(NSString *)getSocialId;

Returns the Social ID for the user. Currently the Android SDK only supports Facebook Logins.

-(NSString *)getFirstName;

Returns the first name of the user as received from the Login Server (Facebook/Twitte

-(NSString *)getLastName;

Returns the last name of the user as received from the Login Server (Facebook/Twitter).

-(NSString *)getCurrencyName;

Returns the name of the currency as received.

-(NSString *)getPicture;

Returns the URL of the Profile Picture of the User.

-(NSString *)getGender;

Returns the gender of the logged in user

-(NSString *)getMiddleName;

Returns the last name of the user as received from the Login Server (Facebook/Twitter).

Displaying offers

Class FavcyShop.h

This class is the storage class for all the parameters, that are required by the application. The FavcyShop object will be returned with the associated parameters on calling getOffers() API successfully.

-(NSString *)getShopURL;

Get the URL associated with this shop. The URL can be used to open the shop in a Web view. In order for the user to stay signed in to Favcy, you need to pass the FavcyApp ID and Favcy User Token with the URL.

NSString *favcyShopUrl = [favcyShop getShopURL];

        favcyShopUrl = [NSString stringWithFormat:@"%@?app_id=%@&usertoken=%@",favcyShopUrl,favcyapp_id,favcyusertoken];

-(NSString *)getShopName;

This returns the name of the Shop.

-(NSString *)getShopIcon;

Returns a string containing the URL of the Shop Icon

-(NSString *)getShopId;

This represents the Shop ID as configured in the Favcy Backend. Currently there is no use of this API, but is to be used for future purpose (to support in-App Shops)

-(NSString *)getShopDescription;

The function returns a small description, associated with the shop

-(NSString *)getShopEmail;

The function returns the support email, as configured on the backend for this shop.

-(NSString *)getShopMobile;

This represents the mobile number associated with the shop.

-(NSString *)getShopFaqUrl;

Returns the URL for the FAQ page. When opening the URL, please pass the application ID and user token

NSString *favcyFaqUrl = [favcyShop getShopFaqUrl];

        favcyFaqUrl = [NSString stringWithFormat:@"%@?app_id=%@&usertoken=%@",favcyFaqUrl,favcyapp_id,favcyusertoken];

Class FavcyAction

This class is the storage class for all the parameters, that are required by the application.  will be returned with the associated parameters on calling getActions() API successfully.

The various methods to fetch profile information from FavcyAction are

-(NSString *)getCode;

Get the code associated with action to be used in the PassPoint API.

-(NSString *)getDescription;

This is the description of the Action, to be used for display purpose

                                        

-(NSString *)getPoints;

                                                   

Returns point corresponding to the action, that the user earns on the action.

                                        

                                

Class Favcy.h

The Favcy class is a singleton class, providing the context to the Favcy SDK.

The class method is: 

This method returns the instance of the class.

Usage Example:

Objective-c: Favcy *favcy = [Favcy getInstance];

Swift: let favcy =  Favcy.getInstance()

The public methods are:

-(void)init:(NSString *)favcyAppID completionHandler:(void(^)(id result, id error))completionHandler;

This should be the first function to be called, using the instance of the “Favcy.h”. This function initializes the SDK.

Usage Example:

Objective-c: [favcy init:@"APP_ID" completionHandler:^(id result, id error) {

        if(error) {

                // Handle Error here...

        }

        else {

           // Handle result/success here...

        }

    }];

‘APP_ID’ is a unique application- id for your application.

-(void)login:(UIViewController *)controller completionHandler:(void(^)(id result, iderror))completionHandler;

The function is used to Login the user into Favcy.

Usage Example:

Objective-c: Favcy *favcy = [Favcy getInstance];

    [favcy login:self completionHandler:^(id result, id error) {

        if(error) {

           // Handle Error here...

        }

        else{

           // Handle result/success here...

        }

    }];

‘self’ represents the UIViewController from where the function is being called.

-(void)logout;

The function is used to Logout the user from Favcy.

Usage Example:

Objective-c: Favcy *favcy = [Favcy getInstance];

[favcy logout];

-(FavcyProfile *)getProfile;

The function returns an object of the FavcyProfile, which provides data and methods to fetch user as well as brand information.

-(NSString *)getFavcyAppId;

The function returns the appId stored with the SDK.

-(BOOL)isLoggedIn;

This function returns true, if the user is successfully logged in and false otherwise.

Please note, that this function should be called post calling the Init API to confirm, if the user is already logged in or not.

-(void)getOfferShops:(void(^)(id result, id error))completionHandler;

This function is used to provide a list of the different Favcy Shops that are available to the brand. Each Shop in the List provides the URL to the Shop, which can be opened in the WAP view. The URL also need to be appended with favcy user token and appID as parameters, for the user to stay logged in into Favcy.

Usage Example:

Objective-c: Favcy *favcy = [Favcy getInstance];

    [favcy getOfferShops:^(NSArray *result, id error) {

         if(error) {

           // Handle Error here...

        }

        else{

           // Handle result/success here...

        }

    }];

-(void)passPoints:(NSString *)actionCode completionHandler:(void(^)(id result, id error))completionHandler;

This function is used to pass user brand points. The brand points are passed based on the action_codes (for both standard actions and the custom actions), as configured on the Admin Panel.

Please note the custom actions, when configured on the admin panel are approved by Favcy Administrators, before they can be used.

Usage Example:

Objective-c:  [favcy passPoints:@"Facebook_Liked" completionHandler:^(id result, id error) {

        if(error) {

           // Handle Error here...

        }

        else{

           // Handle result/success here...

        }

    }];

-(void)passPoints:(NSString *)actionCode  optionalParam:(NSString *)optionalParam completionHandler:(void(^)(id result, id error))completionHandler;

Same as the previous function, except optionalParams. The optionalParams applies to some actions where the associated URL is passed. It is recommended that this method with associated URL (or some unique string) in the optionalParams is used.

Usage Example:

Objective-c: [favcy passPoints:@"Facebook_Liked" optionalParam:@"optional" completionHandler:^(id result, id error) {

               if(error) {

           // Handle Error here...

        }

        else{

           // Handle result/success here...

        }

    }];

-(void)getReferralLink:(void(^)(id result, id error))completionHandler;

This function is used to provide a referral link for the user. The same can be used to forward via, whatsapp, SMS or any other messaging API. The user gets refferal bonus points, every time a user joins the brand on Favcy using the referral link.

                                        

Usage Example:

Objective-c: Favcy *favcy = [Favcy getInstance];

    [favcy getReferralLink:^(id result, id error) {

      if(error) {

           // Handle Error here...

        }

        else{

           // Handle result/success here...

        }

    }];

-(void)getActions:(void(^)(id result, id error))completionHandler

The function is used to get a list of Favcy actions that the application can use and the corresponding configuration on the Favcy Eco System. Please refer the FavcyAction class description for methods of the FavcyAction class.

                                                

Usage Example:

Objective-c: Favcy *favcy = [Favcy getInstance];

    [favcy getActions:^(id result, id error) {

      if(error) {

           // Handle Error here...

        }

        else{

           // Handle result/success here...

        }

    }];

-(void)refreshProfile:(void(^)(id result, id error))completionHandler

This function is used to refresh the user profile.

-(void)refreshProfile {

Favcy *favcy = [Favcy getInstance];

[favcy refreshProfile:^(id result, id error) {

       if(error) {

           // Handle Error here...

        }

        else{

           // Handle result/success here...

        }

    }];

}

        

                                

Use Cases

Login

In order to Login, please call the method Login of the class Favcy from within a controller.

PREREQUISITE: Init function must be called before calling this API.

/* Sample Code for Login on a button click */

-(IBAction)loginButtonTapped:(id)sender {
 
Favcy *favcy = [Favcy getInstance];

    [favcy login:self completionHandler:^(id result, id error) {

        if(error) {

            FavcyError *errorObject = error;

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sorry!" message:errorObject.getErrorMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

            [alert show];

        }

        else{

            FavcyProfile *favcyProfile = result;

            self.lblUserName.text = favcyProfile.getFullName;

            NSURL *pictureURL = [NSURL URLWithString:favcyProfile.getPicture];

            [self.profileImage setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:pictureURL]]];

        }

    }];
}

Passing Brand Points to the User

All Users on Sign up to a brand are credited 100 Brand Points, at the same time 100 Brand Points are credited to the Brand Float. The developer can identify activities for which the user can be given more brand points.

In order to pass points for an action, the PassPoints API need to be called

Below is the sample code for passing brand points to the user for standard action “Facebook_Share”.

-(IBAction)passCoinsButtonTapped:(id)sender {

Favcy *favcy = [Favcy getInstance];

    [favcy passPoints:@"Facebook_Liked" completionHandler:^(id result, id error) {

        if(error) {

            FavcyError *errorObject = error;

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sorry!" message:errorObject.getErrorMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

            [alert show];

        }

        else {

            NSString *points = result;

            NSLog(@"result Points %@", points);

        }

    }];

}

Displaying Offers

The Users can avail the different offers that are available for a brand. In order to let users see and avail offers, the application needs to fetch a list of available offers shops. The API returns a list of offers shops along with their respective URLs. The application can open the URL in an in-App browser for the user to browse and avail offers.

The sample code for Fetching the OfferShops is :

-(IBAction)getOffersButtonTapped:(id)sender {

    Favcy *favcy = [Favcy getInstance];

    [favcy getOfferShops:^(NSArray *result, id error) {

        if(error) {

            FavcyError *errorObject = error;

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sorry!" message:errorObject.getErrorMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

            [alert show];

        }

        else {

            NSArray *favcyShops = result;

            for (int i = 0; i < favcyShops.count; i++) {

                FavcyShop *favcyShop = [[FavcyShop alloc] init];

                favcyShop  = [favcyShops objectAtIndex:i];

               

                NSLog(@"Shop Name %@", favcyShop.getShopName);

            }

        }

    }];

}

Fetching User Referral Link

-(IBAction)referralLinkButtonTapped:(id)sender {

  Favcy *favcy = [Favcy getInstance];

    [favcy getReferralLink:^(id result, id error) {

        if(error) {

            FavcyError *errorObject = error;

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sorry!" message:errorObject.getErrorMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

            [alert show];

        }

        else {

            NSString *URL = result;

            NSLog(@"url %@",URL);

        }

    }];

}

Fetching Action Settings

-(IBAction)getActionButtonTapped:(id)sender {

    Favcy *favcy = [Favcy getInstance];

    [favcy getActions:^(id result, id error) {

        if(error) {

            FavcyError *errorObject = error;

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sorry!" message:errorObject.getErrorMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

            [alert show];

        }

        else{

            NSArray *actionsArray = result;

            for (int i = 0; i < actionsArray.count; i++) {

                FavcyAction *favcyAction = [[FavcyAction alloc] init];

                favcyAction  = [actionsArray objectAtIndex:i];

               

                NSLog(@"Name-- %@  and Points-- %@", favcyAction.getDescription,favcyAction.getPoints);

            }

        }

    }];

}


IOS SDK Developer Guide (Confidential)

Revision: v0.1                                                

Copyright © : Experience Global Mobile Technologies Pvt Ltd.