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!

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. configure accepts the following arguments:
    • 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.
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:
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)
}
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];
    }];
}
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];
}