One of the most important features of YesGraph iOS SDK is the ability to use custom Share Sheet to invite users to your application.

YesGraph iOS SDK currently supports three sharing services out of the box:

  • Facebook,
  • Twitter,
  • Invitation with Emails and Phone Numbers from Contact Book.

Before you can use the Share Sheet, you must authenticate with YesGraph and decide which sharing services will be used in your application.

Facebook Share Service

The Facebook Share Service will ask the user to post a message on their wall using iOS built-in Facebook functionality. To use this service, you do not need an application registered with Facebook. The Facebook Sharing service is implemented in the YSGFacebookService class.

The following code creates a new Facebook Share Service, ready to be used with YSGShareSheetController.

let facebookService = YSGFacebookService()
YSGFacebookService *facebookService = [YSGFacebookService new];

Twitter Share Service

Twitter sharing service will ask the user to tweet a message. Twitter sharing service uses built-in Twitter capabilities of iOS. Similar to Facebook, to use the service, an application does not need to be registered on Twitter, as only logged in user in the device settings is required.

The following code creates a new Twitter Share Service, ready to be used with YSGShareSheetController.

let twitterService = YSGTwitterService()
YSGTwitterService *facebookService = [YSGTwitterService new];

Invitation Share Service

The Invitation Share Service is the most complex sharing service. It allows you to send invites by Email or Messages application (depending on the specific selected contacts). It also requires the user to allow application to access the contact book on the device.

To instantiate the Invitation Share Service, there are is an additional requirement:

YesGraph SDK uses three contact sources:

  • Online Contact Source - uses cached contact source and local contact source and caches ranked contacts from YesGraph API.
  • Cache Contact Source - caches ranked contacts on local device.
  • Local Contact Source - local device contact book.

While you can use the Invitation Share Service with a simple Local Contact Source, we recommend using Online Contact Source which also provides suggestions for invitations using YesGraph Algorithm. To instantiate an Online Source, you need a fully configured YSGClient, YSGCacheContactSource and YSGLocalContactSource which communicates with YesGraph API.

The code below instantiates the Invitation Share Service with all three contact sources.

let userId = "<USER_ID>"
let client = YSGClient(clientKey: "<CLIENT_KEY>")

let localSource = YSGLocalContactSource()
let cacheSource = YSGCacheContactSource()

let onlineSource = YSGOnlineContactSource(client:client, localSource: localSource, cacheSource: cacheSource)
onlineSource.userId = userId

let inviteService = YSGInviteService(contactSource: onlineSource, userId: userId)
NSString *userId = @"<USER_ID>";
YSGClient* client = [[YSGClient alloc] initWithClientKey:@"<CLIENT_KEY>"];

YSGLocalContactSource *localSource = [YSGLocalContactSource new];
YSGCacheContactSource* cacheSource = [YSGCacheContactSource new];

YSGOnlineContactSource *onlineSource = [[YSGOnlineContactSource alloc] initWithClient:client localSource:localSource cacheSource:cacheSource];
onlineSource.userId = userId;

YSGInviteService *inviteService = [[YSGInviteService alloc] initWithContactSource:onlineSource userId:userId];

Using the Share Sheet

YesGraph Share Sheet is a Core component of the SDK and is implemented in YSGShareSheetController class, which is a normal UIViewController.

YSGShareSheetController uses delegates to notify of any changes and actions happening on Share Sheet. The actions are defined in YSGShareSheetDelegate protocol.

The code below instantiates a share sheet:

let shareController = YSGShareSheetController(services: [ facebookService, inviteService ], delegate:nil, theme:nil)
YSGShareSheetController *shareController = [[YSGShareSheetController alloc] initWithServices:@[ facebookService, inviteService ] delegate:nil theme:nil];

You can easily display YSGShareSheetController in a UINavigationController or as a modal view controller.

// Modal
let navController = UINavigationController.init(rootViewController: shareController!)
self.presentViewController(navController, animated: true, completion: nil)
// Navigation
self.navigationController?.pushViewController(shareController!, animated: true)
// Modal
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:shareController];
[self presentViewController:navController animated:YES completion:nil];
// Navigation
[self.navigationController pushViewController:shareController animated:YES];

Usually all sharing services are required on Share Sheet, so YesGraph iOS SDK provides a convenience API in YesGraph class to automatically create and configure the YSGShareSheetController.

let shareController = YesGraph.shared().shareSheetControllerForAllServicesWithDelegate(nil)
YSGShareSheetController *shareController  = [[YesGraph shared] shareSheetControllerForAllServicesWithDelegate:nil];

This convenience method provides an out-of-the-box experience as it will instantiate all sharing services and all contact sources for invite service automatically.