Wix Answers Mobile SDK for iOS

The Wix Answers iOS SDK enables your users to access the Wix Answers widget from inside your application. Your users will have access to all of the existing widget features:
  • Live chat
  • KB articles
  • Contact form
  • Request callback
  • and more!

Usage

Setup

  1. Download the library in one of the following ways:
    • Cocoapods - Add pod 'WixAnswersSDK' to your Podfile.
    • Manual download
      • Download the SDK and unzip it.
      • In XCode, drag the unzipped directory to the root of your project.
      1. Select project settings and select your app's target. In Frameworks, Libraries and Embedded Content, select Embed Without Signing for the WidgetSDK.framework.
  2. Currently, the Wix Answers widget SDK does not officially support anonymous users. Ensure that you enable SSO Authentication in the Advanced tab in the widget settings (at the bottom).
  3. To set up your connection to Wix Answers, call the configure method, with the following parameters:
    • Account name
    • Widget ID
    • An authentication callback - The Wix Answers widget will call this callback to receive a secure token. You must implement this callback to call your server to perform the authentication. See this article for details. The callback will receive an object with a setUserToken that accepts a string. Once you acquire a token for the current user, use that method to set it in the SDK.
    • Locale
To find your account name and widget ID, open the Widget configuration page and edit a specific widget in the Wix Answers back office. Copy the information from the URL, for example: https://[ACCOUNT_NAME].wixanswers.com/app/settings/widgets/[WIDGET_ID]/content/en

To call the configure method, add the following code in your application delegate file. Replace "<locale>" with a language code string to load the widget in that language. If you remove this parameter, the default language is English ("en").
Swift
1
2
3
4
5
import WidgetSDK

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    Widget.configure(withAccountName: "myAccountName", widgetId: "myWidgetId", authenticationCallback: userAuthenticationCallback, locale: "<locale>")
}
Objective C
1
2
3
4
5
6
7
#import "WidgetSDK/Widget.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [Widget configureWithAccountName:@"myAccountName" widgetId:@"myWidgetId" authenticationCallback: ^(AuthResultCallback callback) {
        [Auth authUser:callback];
    } locale:@"<locale>"];
}
4. You can now open the Widget using:
Swift
1
Widget.open()
Objective C
1
[Widget open];

Push Notifications

To receive new chat messages as push notifications:
  1. Configure your application to support push notifications, according to Apple's APNS documentation.
  2. Export your APNS certificate: open the keychain application on your Mac. Select login at the top left and then My Certificates at the bottom left. Export both the Apple Push Services certificate and the private key to two different files.
  3. Run openssl pkcs12 -in [FILENAME].p12 -out [FILENAME].pem -nodes for both the certificate and the private key.
  4. Send the results to mobilesdk@wixanswers.com along with your tenant name.
  5. Request push notification permissions from the user:
Swift
1
2
3
4
5
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]){ (granted, error) in
      DispatchQueue.main.async(execute:UIApplication.shared.registerForRemoteNotifications)
  }
}
Objective C
1
2
3
4
5
6
7
8
9
10
#import <UserNotifications/UserNotifications.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
     UNUserNotificationCenter *notificationCenter = [UNUserNotificationCenter currentNotificationCenter];
     [notificationCenter requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error) {
         dispatch_async(dispatch_get_main_queue(), ^{
             [application registerForRemoteNotifications];
         });
     }];
}
6. Register the device token with Wix Answers.
Swift
1
2
3
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  Widget.setDeviceToken(deviceToken)
}
Objective C
1
2
3
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  [Widget setDeviceToken:deviceToken];
}

Methods

onLoaded(callback:function)

Run a block or code after the widget is loaded. Call this before configure.

Return: None
1
2
3
[Widget onLoaded:^{
  // Code Goes Here...
}];

openWidget()

Display the widget.

Return: None
1
[Widget openWidget];

setDeviceToken(token:NSData)

Register the device token on Wix Answers for notifications.

Return: None
1
[Widget setDeviceToken:@"1234"];

setFeaturedArticles(articles:NSArray of NSStrings)

Dynamically set the featured articles in the widget. You must call this in an onLoaded block before displaying the widget (openWidget).

Return: None
1
2
NSArray *myArray = @[@"fef78571-7a8c-4fa9-b48c-8f106fa16ca8"];
[Widget setFeaturedArticles:myArray];