In-App Chat

This page covers the APIs specific to in-app chats for iOS apps.

Push Notifications

You can set Instabug to send your app a push notification each time a new chat message is received.

Push Certificate

Follow the steps below to upload your push certificate to your Instabug dashboard.

  1. Follow this tutorial to generate a push certificate and export it to a .pem file.
  2. Go to the Push Notifications page on your Instabug dashboard and upload your .pem file.
  3. Select whether the certificate you're uploading is for development or production, and enter the pass phrase if you have set one.

Setting Your App to Handle Instabug Notifications

In application:didRegisterForRemoteNotificationsWithDeviceToken:, pass the token you get to Instabug:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    [Instabug didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    Instabug.didRegisterForRemoteNotifications(withDeviceToken: deviceToken)
}

When you receive a notification, check if it's an Instabug notification, then pass it to Instabug if necessary:



(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    BOOL isInstabugNotification = [Instabug didReceiveRemoteNotification:notificationDictionary];
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
    if Instabug.isInstabugNotification(userInfo) {
        Instabug.didReceiveRemoteNotification(userInfo)
    }
}

And finally, handle when your application has been launched from an Instabug notification. Add the following to application:didFinishLaunchingWithOptions::

NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

BOOL isInstabugNotification = [Instabug didReceiveRemoteNotification:notificationDictionary];
if let notification = launchOptions?[.remoteNotification] as? [String: AnyObject],
    Instabug.isInstabugNotification(notification) {
    Instabug.didReceiveRemoteNotification(notification)
}

Disabling Push Notifications

Push notifications are enabled by default if you upload a push certificate to you Instabug dashboard. To disable them, use the following method:

[Instabug setPushNotificationsEnabled:NO]
Instabug.setPushNotificationsEnabled(false)

In-app Notifications

By default, a notification will be shown on top of your app's UI when a new message is received.

Disabling In-App Notifications

Use the following method to disable notifications that appear in-app.

Instabug.replyNotificationsEnabled = NO;
Instabug.replyNotificationsEnabled = false

Get Unread Messages Count

You can use the following method to get the amount of messages the user has yet to read.

NSUInteger messageCount = Instabug.unreadMessagesCount
let messageCount = Instabug.unreadMessagesCount

SDK Events

New Received Message

This block is executed each time a new message is received. This can be used to show your own UI when a new message is received when default chat notifications are disabled.

Instabug.didRecieveReplyHandler = ^{
    // Notify users about new message.
};
Instabug.didRecieveReplyHandler {
    // Notify users about new message.
}

Enabling and Disabling

Bug reporting, feedback, and chats can be enabled or disabled separately. When the user invokes the SDK with any of the invocation events, a popup appears showing all the enabled features. When only a single option is enabled, it becomes the default invocation mode and the popup doesn't appear. If all options are disabled, bug reporting becomes the default invocation mode.

IBGBugReporting.promptOptions = IBGPromptOptionBug | IBGPromptOptionFeedback;
BugReporting.promptOptions = [.bug, .feedback]

By default, all three options for in-app chats are enabled if they are available in your current plan.