Hello 👋 How can we help?

Add the HelpCrunch iOS SDK to your app

You can add the HelpCrunch SDK to your iOS application manually or with either CocoaPods or Carthage.
Written by Andrew
Updated 2 weeks ago

CocoaPods

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. It has over 43 thousand libraries and is used by over 3 million apps. CocoaPods can help you scale your projects elegantly. If you haven’t used it before, please start here.

To integrate HelpCrunch into your Xcode project with the help of CocoaPods, specify it in your Podfile (the text file in your Xcode project directory named Podfile):

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '11.0'
use_frameworks!
target 'ProjectTargetName' do
  pod 'HelpCrunchSDK'
end

Now, you can install the dependencies in your project:

$ pod install

Make sure to always open the Xcode workspace instead of the project file when building your project:

$ open App.xcworkspace

Carthage

Carthage is another way to add frameworks to your Cocoa application. It builds your dependencies and provides you with binary frameworks, but you keep full control over your project's structure and setup. Carthage does not automatically modify your project files or your build settings.

If you haven’t installed it yet, please check the Installation Quick Start.

Create a Cartfile in the same directory where your .xcodeproj or .xcworkspace is.

Open the Cartfile and add the following:

github "Fishkiller/helpcrunchtestcarthage"

...then run the following:

$ carthage update --platform ios

Open General settings.

Drag the built HelpcrunchSDK.framework, SocketIO.framework and Starscream.framework binaries from Carthage/Build/iOS into the Embedded Binaries section. Don’t forget to select 'Copy items' if needed.

Manual installation

Manual installation will require to do several extra steps in order to install our SDK.

1. Download HelpcrunchSDK.framework from GitHub and copy it into the
Embedded Binaries section. Don’t forget to select 'Copy items' if needed.

2. Next, you need to add our dependencies – Socket.IO and Starscream. You can choose either option depending on how you want to install it.

3. And the last step would be to create a new “Run Script Phase” in “Build Phases”. Add the following line to the script field:

 bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/HelpCrunchSDK.framework/strip-frameworks.sh"

You need to this, to fix (App Store submission bug)[http://www.openradar.me/radar?id=6409498411401216].

Setup code

1. Add the following import to the top of the AppDelegate.m:

ObjC:

@import HelpCrunchSDK;

Swift:

import HelpCrunchSDK

2. Initialize the Helpcrunch SDK Configuration:

ObjC:

HCSConfiguration *configuration =
[HCSConfiguration configurationForOrganization:@"YOUR_HELPCRUNCH_SUBDOMAIN"
applicationId:@"YOUR_APP_ID"
applicationSecret:@"YOUR_APP_SECRET"];

Swift:

let configuration =
HCSConfiguration(forOrganization: "YOUR_HELPCRUNCH_SUBDOMAIN",
applicationId: "YOUR_APP_ID",
applicationSecret: "YOUR_APP_SECRET")

3. Initialize the SDK with configuration.

ObjC:

[HelpCrunch initWithConfiguration:configuration
user:nil
completion:^(NSError * _Nullable error) {
// Do something on SDK init completion
}];

Swift:

HelpCrunch.initWith(configuration, user: nil) { (error) in
// Do something on SDK init completion
}

You can copy this code in the apps list in your HelpCrunch account.

4. To show the HelpCrunch UI simply call the showFromController helper method on HelpCrunch:

ObjC:

[HelpCrunch showFromController:viewController completion:^(NSError * _Nullable error) {
// If you need to do something on completion of SDK view controller presenting
}];

Swift:

HelpCrunch.show(from: viewController) { (error) in
// If you need to do something on completion of SDK view controller presenting
}

viewController is required for the controller to be presented from.

5. You can check if chat is currently displayed using:

ObjC:

[HelpCrunch isVisible]

Swift:

HelpCrunch.isVisible()

6. After you have called the showFromController method, your chat widget will look like this:

Update Info.plist

In order to send files and photos, you need to have NSCameraUsageDescription, NSPhotoLibraryAddUsageDescription and NSPhotoLibraryUsageDescription entries in your Info.plist.

These entries are required by Apple. Users will be prompted to the Camera/Photo Library permissions with your provided text only when they try to use their camera or open/save images to the Photo Library.

  • NSCameraUsageDescription – When a user tries to use the Camera.
  • NSPhotoLibraryUsageDescription – When a user tries to open the Photo Library.
  • NSPhotoLibraryAddUsageDescription – When a user tries to save image to the Photo Library.

Did this answer your question?