Happy Halloween 🎃 How can we help?

Add the HelpCrunch iOS SDK to your app

You can add the HelpCrunch SDK to your iOS application manually as well as with CocoaPods or Carthage.
Written by Andrew
Updated 4 months 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', '~> 3.0'
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.

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

2. Open the Cartfile and add the following:

github "helpcrunch/helpcrunchsdk-ios" ~> 3.0

3. ...then run the following:

$ carthage update --platform ios

4. Open General settings.

5. 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 the 'Copy items' option if needed.

Manual installation

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

1. Download the HelpcrunchSDK.framework from GitHub and copy it into the Embedded Binaries section. Don’t forget to select the 'Copy items' option 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 the “Build Phases”. Add the following line to the script field:

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

You need 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 from the apps list in your HelpCrunch account.

4. You can always check the state enum to get a current SDK state. It could be Idle, Loading, Error, UserIsBlocked or Ok, so you can show or disable your 'Contact Us' button appropriately. Also there is the HCSStateChangedNotification notification event to keep you up to date.

ObjC:

[HelpCrunch state]

Swift:

HelpCrunch.state()

5. 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.

6. You can check if your chat is currently displayed using:

ObjC:

[HelpCrunch isVisible]

Swift:

HelpCrunch.isVisible()

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

8. If needed, you can close the HelpCrunch chat automatically simply by calling closeChatWithCompletion method

Update Info.plist

In order to send files and photos, you need to have the NSCameraUsageDescription, NSPhotoLibraryAddUsageDescription and NSPhotoLibraryUsageDescription entries in your Info.plist. These entries are required by Apple.

Users will see the corresponding text that you provide and will be prompted to their Camera/Photo Library permissions when they try to use their camera or open/save images to the Photo Library.

  • NSCameraUsageDescription – When users try to use their Camera.
  • NSPhotoLibraryUsageDescription – When users try to open their Photo Library.
  • NSPhotoLibraryAddUsageDescription – When users try to save images to their Photo Library.

Did this answer your question?