Advice and answers from the Intercom Team

Install Intercom to see and talk to users of your iOS app. The Intercom for iOS library supports iOS 8.x and upwards. 

Note: If you already use Intercom for iOS, here’s how to upgrade to the new Messenger

Step 1 - Install Intercom

If you’re new to Intercom, you’ll need to create an account and start your free trial. Then you have three options: 

Option 1: Install Intercom with CocoaPods

1. Add the Intercom to your Podfile, like this:

target :YourTargetName do
  pod 'Intercom'
end

2. Now run pod install 

Option 2. Install with Carthage

  1. Add github "intercom/intercom-ios" to your Cartfile .
  2. Run carthage update.
  3. Go to your Xcode project's "General" settings. Drag Intercom.framework from Carthage/Build/iOS to the "Embedded Binaries" section.

Option 3: Install Intercom manually 

  1. Download Intercom for iOS and extract the zip.
  2. Go to your Xcode project's "General" settings. Drag Intercom.framework to the "Embedded Binaries" section. Make sure “Copy items if needed” is selected and click Finish.
  3. Finally, you'll need to work around an App Store submission bug. To do this, create a new “Run Script Phase” in your app’s target’s “Build Phases” and paste the following snippet in the script text field:
bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/Intercom.framework/strip-frameworks.sh"

iOS 10 requirements

If you are supporting iOS 10 in your app, you'll need to make sure that you add NSPhotoLibraryUsageDescription to your Info.plist so that your users have the ability to upload photos in Intercom's messenger. This is a new permissions requirement from Apple in iOS 10.

Step 2 - Initialize Intercom 

First, you'll need to get your Intercom app ID and iOS API key. To find these, just select the 'Intercom for iOS' option in your app settings.

Then initialize Intercom by adding the following to your application delegate:

In Objective-C:

First, import Intercom with: @import Intercom; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [Intercom setApiKey:@"<Your iOS API Key>" forAppId:@"<Your App ID>"];
}

In Swift:

First, import Intercom with: import Intercom 


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
     Intercom.setApiKey("<Your iOS API Key>", forAppId: "<Your App ID>")
}

Step 3 - Register your users

You’ll need to register your users with Intercom before you can talk to them or see what they do in your app. Depending on the type of app you have, you can register logged in users of your app, logged out users of your website or both. Here’s tailored instructions for each option: 

Register your logged in users 

If you have an app with logged in (identified) users only (like Facebook, Instagram or Slack) follow these instructions: 

1. First, you’ll need to register your user when your app launches, like this: 

In Objective-C:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    if(loggedIn){
        [Intercom registerUserWithUserId:@"<#123456#>"];
    }
}

In Swift:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    if loggedIn {
      Intercom.registerUser(withUserId: "<#123456#>")
    }
}

Note: If you don't have a unique userId to use here, or if you have a userId and an email you can use [Intercom registerUserWithEmail:@"user@exampleapp.com"]; or [Intercom registerUserWithUserId:@"<#123456#>" email:@"user@exampleapp.com"]; 

2. You’ll also need to register your user anywhere they log in: 

In Objective-C:

- (void)successfulLogin {
    [Intercom registerUserWithUserId:@"<#123456#>"];
}

In Swift:

func successfulLogin() {
    Intercom.registerUser(withUserId: "<#123456#>")
}

Register your logged out users 

If you have an app with logged out (unidentified) users only (like Angry Birds or a flashlight app), follow these instructions:

Just register an unidentified user in your application's delegate, like so:

In Objective-C:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [Intercom registerUnidentifiedUser];
}

In Swift:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
     Intercom.registerUnidentifiedUser()
}

Register your logged in and logged out users

If you have an app with both logged in and logged out users (like Google Maps or YouTube), follow these instructions: 

1. First, you’ll need to register your user when your app launches, like this: 

In Objective-C:

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    if(loggedIn){
        [Intercom registerUserWithUserId:@"<#123456#>"];
    } else {
        [Intercom registerUnidentifiedUser];
    }
}

In Swift:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    if loggedIn {
        Intercom.registerUser(withUserId: "<#123456#>")
    } else {
        Intercom.registerUnidentifiedUser()
    }
}

Note: If you don't have a unique userId to use here, or if you have a userId and an email you can use [Intercom registerUserWithEmail:@"user@exampleapp.com"]; or [Intercom registerUserWithUserId:@"<#123456#>" email:@"user@intercom.com"]; 

2. You’ll also need to register your user anywhere they log in: 

In Objective-C:

-(void)successfulLogin {
    [Intercom registerUserWithUserId:@"<#123456#>"];
}

In Swift:

func successfulLogin() {
     Intercom.registerUser(withUserId: "<#123456#>")
}

How to unregister a user 

When users want to log out of your app, simply call:

In Objective-C:

- (void)logout {
    [Intercom reset];
}

In Swift:

func logout() {
    Intercom.reset()
}

Best practices for registering users 

  1. Don’t use an email address as a userId as this field is unique and cannot be changed or updated later. If you only have an email address, you can just register a user with that.
  2. If you register users with an email address, the email must be a unique field in your app. Otherwise we won't know which user to update and the mobile integration won't work.

Note: Intercom knows when your app is backgrounded and comes alive again, so you won’t need to re-register your users.

What next?

  1. Once you've got Intercom installed it's time to configure it for your iOS app
  2. Enable push notifications so you can send push messages.
  3. Enable secure mode for your iOS app.
Did this answer your question?