Skip to main content

Pre-requisites

  • ASAPP iOS SDK 9.4.0 or later, correctly configured and initialized see more here.

Getting Started

Once you’ve successfully configured and initialized the ASAPP SDK, you can start using Chat Instead for iOS.
  1. Create a New Instance.
    let chatInsteadViewController =  ASAPPChatInsteadViewController(phoneNumber: phoneNumber, delegate: delegate, title: title, chatIcon: image)
    
    phoneNumber (required)The phone number to call when the phone channel is selected. Must be a valid phone number. For more information, see Apple’s documentation on phone links.
    delegate (required)An object that implements ASAPPChannelDelegate.
    title (optional)A title (also called the “Chat Instead header title”) which is displayed at the top of the Chat Instead UI. (See Customization)
    image (optional)A UI Image that will override the default image for the chat channel. (See Customization)
  2. Implement two functions that the ASAPPChannelDelegate requires:
    func channel(_ channel: ASAPPChannel, didFailToOpenWithErrorDescription errorDescription: String?)
    
    ASAPP calls this if an error occurs while trying to open a channel.
    func didSelectASAPPChatChannel()
    
    This opens the ASAPP chat. You should use one of these methods:
    ASAPP.createChatViewControllerForPresentingFromChatInstead()
    
    or
    ASAPP.createChatViewControllerForPushingFromChatInstead()
    
    to present or push the view controller instance that ASAPP returned. This means that you must present/push the ASAPP chat view controller inside didSelectASAPPChatChannel().
ASAPP highly recommends initializing ASAPPChatInsteadViewController as early as possible for the best user experience.
Whenever a channel is selected, ASAPP handles everything by default (except for the chat channel), but you can also handle a channel by yourself by implementing func shouldOpenChannel(_ channel: ASAPPChannel) -> Bool and returning false.
  1. Show the chatInsteadViewController instance by using:
    present(chatInsteadViewController, animated: true)
    
Only presentation works. Pushing the chatInsteadViewController instance does not work and causes unexpected behavior.

Support for iPad

For the best user experience, you should configure popover mode, which is used on iPad. Use the .popover presentation style and set both the sourceView and sourceRect properties following Apple’s conventions:
chatInsteadViewController.modalPresentationStyle = .popover
chatInsteadViewController.popoverPresentationController?.sourceView = aView
chatInsteadViewController.popoverPresentationController?.sourceRect = aRect
This will only have an effect when your app is run on iPad.
If you set modalPresentationStyle to .popover and forget to set sourceView and sourceRect, the application will crash in runtime. So please be sure to set both if you’re using the popover mode.

Customization

You can customize the Chat Instead header title and the chat icon when creating the ASAPPChatInsteadViewController instance. (See Getting Started.
ASAPPChatInsteadViewController uses ASAPPColors for styling, so it will automatically use the colors set there (e.g. primary, background, onBackground, etc.), which are the same colors used for customizing the ASAPP chat interface. There is no way to independently change the styling of the Chat Instead UI.
ASAPP supports Dark Mode by default as long as you enable it.

Remote settings

When you create an instance of ASAPPChatInsteadViewController, it automatically fetches remote settings to indicate which channels to display. You can configure these settings.
These remote settings override local ones (i.e. the ones you pass in when creating the ASAPPChatInsteadViewController instance).
If an error occurs while fetching the settings and no local values were set, the system uses the defaults.

Cache

When fetching succeeds, the SDK caches the remote settings for a short period of time. This cache references in lieu of repeated fetches. The cache remains valid across multiple app sessions.