iOS Advanced Features

Create Content Reference

let buo = BranchUniversalObject.init(canonicalIdentifier: "content/12345")
buo.title = "My Content Title"
buo.contentDescription = "My Content Description"
buo.imageUrl = ""
buo.publiclyIndex = true
buo.locallyIndex = true
buo.contentMetadata.customMetadata["key1"] = "value1"
BranchUniversalObject *buo = [[BranchUniversalObject alloc] initWithCanonicalIdentifier:@"content/12345"];
buo.title = @"My Content Title";
buo.contentDescription = @"My Content Description";
buo.imageUrl = @"";
buo.publiclyIndex = YES;
buo.locallyIndex = YES;
buo.contentMetadata.customMetadata[@"key1"] = @"value1";

Creating dynamic links without the share sheet

If you've built your own share sheet and you want to just create a Branch link for an individual share message or have another use case, you can create deep links directly with the following call:

[branchUniversalObject getShortUrlWithLinkProperties:linkProperties andCallback:^(NSString *url, NSError *error) {
        if (!error) {
            NSLog(@"got my Branch invite link to share: %@", url);
branchUniversalObject.getShortUrl(with: linkProperties) { (url, error) in
        if (error == nil) {
            print("Got my Branch link to share: (url)")
        } else {
            print(String(format: "Branch error : %@", error! as CVarArg))

You can find examples of linkProperties above. You would next use the returned link and help the user post it to (in this example) Facebook.

Specifying a shared email subject

The majority of share options only include one string of text, except email, which has a subject and a body. The share text will fill in the body and you can specify the email subject in the link properties as shown below.

BranchLinkProperties *linkProperties = [[BranchLinkProperties alloc] init];
    linkProperties.feature = @"share"; = @"facebook";
    [linkProperties addControlParam:@"$email_subject" withValue:@"Your Awesome Deal"];
let linkProperties: BranchLinkProperties = BranchLinkProperties()
    linkProperties.feature = "share" = "facebook"
    linkProperties.addControlParam("$email_subject", withValue: "Your Awesome Deal")

Create Link Reference

let lp: BranchLinkProperties = BranchLinkProperties() = "facebook"
lp.feature = "sharing"
lp.campaign = "content 123 launch"
lp.stage = "new user"
lp.tags = ["one", "two", "three"]

lp.addControlParam("$desktop_url", withValue: "")
lp.addControlParam("$ios_url", withValue: "")
lp.addControlParam("$ipad_url", withValue: "")
lp.addControlParam("$android_url", withValue: "")
lp.addControlParam("$match_duration", withValue: "2000")

lp.addControlParam("custom_data", withValue: "yes")
lp.addControlParam("look_at", withValue: "this")
lp.addControlParam("nav_to", withValue: "over here")
lp.addControlParam("random", withValue: UUID.init().uuidString)
BranchLinkProperties *lp = [[BranchLinkProperties alloc] init];
lp.feature = @"facebook"; = @"sharing";
lp.campaign = @"content 123 launch";
lp.stage = @"new user";
lp.tags = @[@"one", @"two", @"three"];

[lp addControlParam:@"$desktop_url" withValue: @""];
[lp addControlParam:@"$ios_url" withValue: @""];
[lp addControlParam:@"$ipad_url" withValue: @""];
[lp addControlParam:@"$android_url" withValue: @""];
[lp addControlParam:@"$match_duration" withValue: @"2000"];

[lp addControlParam:@"custom_data" withValue: @"yes"];
[lp addControlParam:@"look_at" withValue: @"this"];
[lp addControlParam:@"nav_to" withValue: @"over here"];
[lp addControlParam:@"random" withValue: [[NSUUID UUID] UUIDString]];

Create Deep Link

buo.getShortUrl(with: lp) { url, error in
        print(url ?? "")
[buo getShortUrlWithLinkProperties:lp andCallback:^(NSString* url, NSError* error) {
    if (!error) {
        NSLog(@"@", url);

Share Deep Link

let message = "Check out this link"
buo.showShareSheet(with: lp, andShareText: message, from: self) { (activityType, completed) in
  print(activityType ?? "")
buo showShareSheetWithLinkProperties:lp andShareText:@"Super amazing thing I want to share!" fromViewController:self completion:^(NSString* activityType, BOOL completed) {
    NSLog(@"finished presenting");

Read Deep Link

  • Retrieve Branch data from a deep link

  • Best practice to receive data from the listener (to prevent a race condition)

  • Returns deep link properties

// listener (within AppDelegate didFinishLaunchingWithOptions)
Branch.getInstance().initSession(launchOptions: launchOptions) { params, error in
  print(params as? [String: AnyObject] ?? {})

// latest
let sessionParams = Branch.getInstance().getLatestReferringParams()

// first
let installParams = Branch.getInstance().getFirstReferringParams()
[[Branch getInstance] initSessionWithLaunchOptions:launchOptions
                        andRegisterDeepLinkHandler:^(NSDictionary * _Nullable params,
                                                     NSError * _Nullable error) {
    if (!error) {
        //Referring params
        NSLog(@"Referring link params %@",params);

// latest
NSDictionary *sessionParams = [[Branch getInstance] getLatestReferringParams];

// first
NSDictionary *installParams =  [[Branch getInstance] getFirstReferringParams];

Navigate to Content

  • Handled within Branch.initSession()
// within AppDelegate application.didFinishLaunchingWithOptions
Branch.getInstance().initSession(launchOptions: launchOptions) { params , error in
  // Option 1: read deep link data
  guard let data = params as? [String: AnyObject] else { return }

  // Option 2: save deep link data to global model
  SomeCustomClass.sharedInstance.branchData = data

  // Option 3: display data
  let alert = UIAlertController(title: "Deep link data", message: "\(data)", preferredStyle: .alert)
  alert.addAction(UIAlertAction(title: "Okay", style: .default, handler: nil))
  self.window?.rootViewController?.present(alert, animated: true, completion: nil)

  // Option 4: navigate to view controller
  guard let options = data["nav_to"] as? String else { return }
  switch options {
      case "landing_page": self.window?.rootViewController?.present( SecondViewController(), animated: true, completion: nil)
      case "tutorial": self.window?.rootViewController?.present( SecondViewController(), animated: true, completion: nil)
      case "content": self.window?.rootViewController?.present( SecondViewController(), animated: true, completion: nil)
      default: break
// within AppDelegate application.didFinishLaunchingWithOptions
[[Branch getInstance] initSessionWithLaunchOptions:launchOptions andRegisterDeepLinkHandler:^(NSDictionary * _Nonnull params, NSError * _Nullable error) {
  // Option 1: read deep link data
  NSLog(@"%@", params);

  // Option 2: save deep link data to global model
  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  [defaults setObject:params.description forKey:@"BranchData"];
  [defaults synchronize];

  // Option 3: display data
  UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"Title" message:params.description preferredStyle:UIAlertControllerStyleAlert];
  UIAlertAction *button = [UIAlertAction actionWithTitle:@"Deep Link Data" style:UIAlertActionStyleDefault handler:nil];
  [alert addAction:button];
  [self.window.rootViewController presentViewController:alert animated:YES completion:nil];

  // Option 4: navigate to view controller
  if ([params objectForKey:@"navHere"]) {
    ViewController *anotherViewController = [[ViewController alloc] initWithNibName:@"anotherViewController" bundle:nil];
    [self.window.rootViewController presentViewController:anotherViewController animated:YES completion:nil];


buo.automaticallyListOnSpotlight = true
buo.automaticallyListOnSpotlight = YES;

Track content

BranchEvent.standardEvent(.viewItem, withContentItem: buo).logEvent()
[[BranchEvent standardEvent:BranchStandardEventViewItem withContentItem:buo] logEvent];

Track Events

  • All events related to a customer purchasing are bucketed into a "Commerce" class of data items

  • All events related to users interacting with your in-app content are bucketed to a "Content" class of data items.

  • All events related to users progressing in your app are bucketed to a "Lifecycle" class of data items.

  • To track custom events - not found in the table below - please see Track Custom Events

  • Validate with the Branch Dashboard

Use the table below to quickly find the event you want to track.

Event NameEvent CategoryiOS
Add To CartCommerce EventBranchStandardEventAddToCart
Add To WishlistCommerce EventBranchStandardEventAddToWishlist
View CartCommerce EventBranchStandardEventViewCart
Initiate PurchaseCommerce EventBranchStandardEventInitiatePurchase
Add Payment InfoCommerce EventBranchStandardEventAddPaymentInfo
PurchaseCommerce EventBranchStandardEventPurchase
Spend CreditsCommerce EventBranchStandardEventSpendCredits
SearchContent EventBranchStandardEventSearch
View ItemContent EventBranchStandardEventViewItem
View ItemsContent EventBranchStandardEventViewItems
RateContent EventBranchStandardEventRate
ShareContent EventBranchStandardEventShare
Complete RegistrationLifecycle EventBranchStandardEventCompleteRegistration
Complete TutorialLifecycle EventBranchStandardEventCompleteTutorial
Achieve LevelLifecycle EventBranchStandardEventAchieveLevel
Unlock AchievementLifecycle EventBranchStandardEventUnlockAchievement

Handle Push Notifications

  • Allows you to track Branch deep links in your push notifications

  • Include the Branch push notification handler in Initialize Branch

  • Add a Branch deep link in your push notification payload

    • Replace with your deep link
  "aps": {
    "alert": "Push notification with a Branch deep link",
    "badge": "1"
  "branch": ""

Handle Links in Your Own App

  • Allows you to deep link into your own from your app itself
Branch.getInstance().handleDeepLink(withNewSession: URL(string: ""))
[[Branch getInstance] handleDeepLinkWithNewSession:[NSURL URLWithString:@""]];


Handling a new deep link in your app

Handling a new deep link in your app will clear the current session data and a new referred "open" will be attributed.

Track Apple Search Ads

  • Allows Branch to track Apple Search Ads deep linking analytics

  • Analytics from Apple's API have been slow which will make our analytics lower. Additionally, Apple's API does not send us all the data of an ad every time which will make ads tracked by us to show a generic campaign sometimes.

  • Add before initSession Initialize Branch

[[Branch getInstance] delayInitToCheckForSearchAds];

Enable 100% Matching

  • Use the SFSafariViewController to increase the attribution matching success

  • The 100% match is a bit of a misnomer, as it is only 100% match from when a user clicks from the Safari browser. According to our analysis, clicking through Safari happens about 50-75% of the time depending on the use case. For example, clicking from Facebook, Gmail or Chrome won’t trigger a 100% match here. However, it’s still beneficial to the matching accuracy, so we recommend employing it.

  • When using a custom domain, add a branch_app_domain string key in your Info.plist with your custom domain
    to enable 100% matching.

  • By default, cookie-based matching is enabled on iOS 9 and 10 if the SafariServices.framework
    is included in an app's dependencies, and the app uses an subdomain or sets the branch_app_domain
    in the Info.plist. It can be disabled with a call to the SDK.

  • Add before initSession Initialize Branch

[[Branch getInstance] disableCookieBasedMatching];

Enable / Disable User Tracking

If you need to comply with a user's request to not be tracked for GDPR purposes, or otherwise determine that a user should not be tracked, utilize this field to prevent Branch from sending network requests. This setting can also be enabled across all users for a particular link, or across your Branch links.

[Branch setTrackingDisabled:YES];

You can choose to call this throughout the lifecycle of the app. Once called, network requests will not be sent from the SDKs. Link generation will continue to work, but will not contain identifying information about the user. In addition, deep linking will continue to work, but will not track analytics for the user.

Share to Email Options

  • Change the way your deep links behave when shared to email

  • Needs a Share deep link

lp.addControlParam("$email_subject", withValue: "Your Awesome Deal")
lp.addControlParam("$email_html_header", withValue: "<style>your awesome CSS</style>\nOr Dear Friend,")
lp.addControlParam("$email_html_footer", withValue: "Thanks!")
lp.addControlParam("$email_html_link_text", withValue: "Tap here")
[lp addControlParam:@"$email_subject" withValue:@"This one weird trick."];
[lp addControlParam:@"$email_html_header" withValue:@"<style>your awesome CSS</style>\nOr Dear Friend,"];
[lp addControlParam:@"$email_html_footer" withValue:@"Thanks!"];
[lp addControlParam:@"$email_html_link_text" withValue:@"Tap here"];

Share Message Dynamically

  • Change the message you share based on the source the users chooses

  • Needs a Share deep link

// import delegate
class ViewController: UITableViewController, BranchShareLinkDelegate

func branchShareLinkWillShare(_ shareLink: BranchShareLink) {
  // choose shareSheet.activityType
  shareLink.shareText = "\("
// import delegate
@interface ViewController () <BranchShareLinkDelegate>

  - (void) branchShareLinkWillShare:(BranchShareLink*)shareLink {
  // choose shareSheet.activityType
  shareLink.shareText = [NSString stringWithFormat:@"@%",];

Return YES to continueUserActivity

When users enter your app via a Universal Link, we check to see to see if the link URL contains If so, handledByBranch will return YES. If not, handledByBranch will return NO. This allows us to explicitly confirm the incoming link is from Branch without making a server call.

For most implementations this will never be an issue, since your deep links will be routed correctly either way. However, if you use a custom link domain and you rely on handledByBranch to return YES for every incoming Branch-generated Universal Link, you can inform the Branch SDK by following these steps:

  1. In your Info.plist file, create a new key called branch_universal_link_domains.
  2. Add your custom domain(s) as a string. imageimage
  3. Save the file.


Multiple custom domains

If you have an unusual situation with multiple custom link domains, you may also configure branch_universal_link_domains as an array of strings. imageimage

Handle links for web-only content


Universal Email Only

If you have links to content that exists only on web, and not in the app (for example, a temporary marketing webpage that isn't in the app) then this code snippet will ensure all links that have not had the deep linking script applied will open in a browser.

You should add this code snippet inside the deep link handler code block. Note that this uses query parameter $web_only=true. This should match the query parameter on the web URL you enter in the email.

[branch initSessionWithLaunchOptions:launchOptions andRegisterDeepLinkHandler:^(NSDictionary *params, NSError *error) {
  // params are the deep linked params associated with the link that the user clicked before showing up.
  if (params[@"$3p"] && params[@"$web_only"]) {
            NSURL *url = [NSURL URLWithString:params[@"$original_url"]];
            if (url) {
                [application openURL:url]; // check to make sure your existing deep linking logic, if any, is not executed, perhaps by returning early
  } else {
    // it is a deep link
    GDLog(@"branch deep link: %@", [params description]);
    [self handleBranchDeeplink:params];
branch.initSession(launchOptions: launchOptions, andRegisterDeepLinkHandler: { (params, error) in
            if (params?["$3p"] != nil && params?["$web_only"] != nil) {
                if let urlString = params?["$original_url"] as? String {
                    if let url = URL(string: urlString) {
            } else {

Set initialization metadata


Data Integration Only

If you are using a 3rd Party Data Integration Partner that requires setting certain identifiers before initializing the Branch SDK, you should add this code snippet:

//Inside *didFinishLaunchingWithOptions*
[[Branch getInstance] setRequestMetadataKey:@"{ANALYTICS_ID}" value: […]];

Replace {ANALYTICS_ID} with your Data Integration Partner's key.

Updated 2 days ago

iOS Advanced Features

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.