Skip to content

Send Your First Smart Invite on iOS

Prerequisite

Send Smart Invites

GetSocial SDK provides two ways to send Smart Invites: using our data API or via provided GetSocial UI.

Smart Invites are powered by Smart Links. Internally we generate a unique Smart Link for each invitation and attach information about the sender to the Smart Link.

You can attach string-string key-value pairs to pass custom data with a Smart Link. Also, you can add one of the predefined parameters to change the behaviour of the Smart Link.

Receiving user can get the data attached to the Smart Link on the app start, even if an app was just installed from the store.

To create link params with key-value pairs you want to attach to the Smart Link:

```objc tab=”Objective-C”
NSDictionary *linkParams = @{
@”custom_key”: @”custom_value”, // custom key
@”$title”: @”Custom landing page title” // predefined key
};

```swift tab="Swift"
let linkParams = [
    "custom_key": "custom_value", // custom key
    "$title": "Custom landing page title" // predefined key
    ]

Supported value types

The linkParams dictionary supports NSString* values for custom data, other types will be ignored.

Customize Invite Message Content

Some invite channels allow to customize text, image and subject. Check the details here.

Default Smart Invites message can be defined on the GetSocial DashboardAcquisition section → Smart Invites tab.

To customize content on the client side:

```objc tab=”Objective-C”
GetSocialMutableInviteContent* inviteContent = [GetSocialMutableInviteContent new];
inviteContent.text = @”I can’t stop playing! Get it here [APP_INVITE_URL]”; // NOTE: if you customize the text [APP_INVITE_URL] placeholder have to be used
inviteContent.subject = @”Check out this app”;
inviteContent.mediaAttachment = [GetSocialMediaAttachment imageUrl:@”https://docs.getsocial.im/images/logo.png”];

```swift tab="Swift"
let inviteContent = GetSocialMutableInviteContent()
inviteContent.text = "I can't stop playing! Get it here [APP_INVITE_URL]" // NOTE: if you customize the text [APP_INVITE_URL] placeholder have to be used
inviteContent.subject = "Check out this app"
inviteContent.mediaAttachment = GetSocialMediaAttachment.imageUrl("https://docs.getsocial.im/images/logo.png")

Send Invites Using GetSocial Data API

The code below shows how to send Smart Invite with custom data and custom content attached via a Facebook channel. All supported Invite Channels are listed in GetSocialConstants.h file with GetSocial_InviteChannelPluginId_ prefix.

```objc tab=”Objective-C”
NSString *inviteChannelId = GetSocial_InviteChannelPluginId_Facebook;

// Check if invite channel is available on the device.
// Alternatively you can get all available channels via [GetSocial inviteChannels]
if([GetSocial isInviteChannelAvailable:inviteChannelId]) {

1
2
3
4
5
6
7
[GetSocial sendInviteWithChannelId:inviteChannelId inviteContent:inviteContent linkParams:linkParams success:^{
    NSLog(@"Invitation with referral data via FACEBOOK was sent");
} cancel:^{
    NSLog(@"Invitation with referral data via FACEBOOK was cancelled");
} failure:^(NSError * _Nonnull error) {
    NSLog(@"Invitation with referral data via FACEBOOK failed, error: %@", error.description);
}];

}
swift tab=”Swift”
let inviteChannelId = GetSocial_InviteChannelPluginId_Facebook

// Check if invite channel is available on the device.
// Alternatively you can get all available channels via GetSocial.inviteChannels()
if GetSocial.isInviteChannelAvailable(inviteChannelId) {

GetSocial.sendInvite(withChannelId: inviteChannelId, inviteContent: inviteContent, linkParams: linkParams, success: {
print(“Invitation with referral data via FACEBOOK was sent”)
}, cancel: {
print(“Invitation with referral data via FACEBOOK was cancelled”)
}, failure: { error in
print(“Invitation with referral data via FACEBOOK failed, error: (error.description)”)
})
}
```

Facebook Share Dialog will be presented as a result:

GetSocial Smart Ivites View

Send Invites Using GetSocial Smart Invites View

GetSocial UI library provide a view that lists all Smart Invite channels available on the device and enabled on the GetSocial Dashboard.

To send an invite with custom data attached using GetSocial UI:

```objc tab=”Objective-C”
GetSocialUIInvitesView* invitesView = [GetSocialUI createInvitesView];

[invitesView setLinkParams:linkParams];
[invitesView setCustomInviteContent:inviteContent];

[invitesView setHandlerForInvitesSent:^(NSString * _Nonnull channelId) {
NSLog(@”Invitation via %@ was sent”, channelId);
} cancel:^(NSString * _Nonnull channelId) {
NSLog(@”Invitation via %@ was cancelled”, channelId);
} failure:^(NSString * _Nonnull channelId, NSError * _Nonnull error) {
NSLog(@”Invitation via %@ failed, error: %@”, channelId, error.description);
}];

BOOL wasShown = [invitesView show];
NSLog(@”GetSocial Smart Invites UI was shown: %d”, wasShown);

```swift tab="Swift"
let invitesView: GetSocialUIInvitesView = GetSocialUI.createInvitesView()

invitesView.setLinkParams(linkParams)
invitesView.setCustomInviteContent(inviteContent)

invitesView.setHandlerForInvitesSent({ channelId in
    print("Invitation via \(channelId) was sent")
}, cancel: { channelId in
    print("Invitation via \(channelId) was cancelled")
}, failure: { channelId, error in
    print("Invitation via \(channelId) failed, error: \(error.description)")
})

let wasShown: Bool = invitesView.show()
print("GetSocial Smart Invites UI was shown: \(wasShown)")

You will see the following view on your screen:

GetSocial Smart Ivites View

[GetSocial sendInviteWithChannelId:...] and [GetSocialUi createInvitesView] are opening the selected invite channel with pre-filled invite message. If you want to handle sharing on your own and just need a Smart Link to invite uses you can use the following API:

```objc tab=”Objective-C”
NSDictionary *linkParams = @{
@”$channel”: “my_custom_channel” // optional: set sharing channel for analytics, by default channel is set to “manual”
};

[GetSocial createInviteLinkWithParams:linkParams
success:^(NSString *_Nonnull smartLink) {
NSLog(YES, NO, @”Created invite url: %@”, smartLink);
}
failure:^(NSError *_Nonnull error) {
NSLog(YES, NO, @”Failed to create invite url, error: %@”, error);
}];

```swift tab="Swift"
let linkParams = [
    "$channel": "my_custom_channel" // optional: set sharing channel for analytics, by default channel is set to "manual"
    ]

GetSocial.createInviteLink(withParams: linkParams, success: { smartLink in
    print("Created invite url: \(smartLink)")
}, failure: { error in
    print("Failed to create invite url, error: \(error)")
})

Next Steps

Give us your feedback! Was this article helpful?

😀 🙁