zoho / SalesIQ-Mobilisten-iOS

Your mobile app's ideal live chat partner. Power up your iOS App with the SalesIQ Mobilisten iOS SDK.
https://mobilisten.io
12 stars 4 forks source link

Question: Invoking ZohoSalesIQ.Chat.show() API does not work prior to SDK initialization. #20

Closed ammarmarn closed 3 years ago

ammarmarn commented 3 years ago

Describe the bug The chat will not open on calling ZohoSalesIQ.Chat.show() if Mobilisten is unable to initialize yet for any undefined reason (no idea why its taking time even if called in appdidFinishLaunching).

To Reproduce That's how we do right now on code:

ZohoSalesIQ.initWithAppKey("....") ZohoSalesIQ.Chat.show()

Expected behavior the chat window should always show or atleast give a error so developer can handle the failure.

Finding If this "✅ MOBILISTEN » INITIALIZED {4.1.0}" is not printed yet the calling "ZohoSalesIQ.Chat.show()" will have no affect.

Rishabh-Raghunath commented 3 years ago

The process of initializing Mobilisten is asynchronous in nature. The initWithAppKey API comes with a completion closure within which the status of initialization is provided.

APIs like ZohoSalesIQ.Chat.show() require that Mobilisten is successfully initialized before invocation. If you wish to open chat immediately after initialization, here is how you can do it;

ZohoSalesIQ.initWithAppKey(appKey, accessKey: accessKey) { (success) in
  if success {
    ZohoSalesIQ.Chat.show()
  }
}

We do have plans to provide an error in return as well in the API. Using the completion closure provided with the initWithAppKey API should resolve your issue.

ammarmarn commented 3 years ago

ok, so do you have any method to check whether SDK is initialized or not? So I can check before calling ZohoSalesIQ.Chat.show(). Incase, I have calling init in AppDelegate for example in order to avoid wait for the user when help button tapped in ViewController.

Rishabh-Raghunath commented 3 years ago

Yes we do. ZohoSalesIQ.Chat.isEnabled can be used to check the state.

ammarmarn commented 3 years ago

Right now faced one more issue, the sdk is initialized while Invoking ZohoSalesIQ.Chat.show() I am getting the following error, and no chat window is visible;

"Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service"

Rishabh-Raghunath commented 3 years ago

Hi @ammarmarn, the message shared is not related to the Chat.show() API or the chat window. Could you share more details on how and where the API is being invoked?

ammarmarn commented 3 years ago

In the ViewController I am initializing the SDK, while when support button is pressed then setting some user info and then showing chat window.

    override func viewDidLoad() {
        ZohoHandler.setupZohoChat()
    }

    @IBAction func supportBtnTapped(_ sender: UIButton) {
        let visitor = VisitorClass.init()
        visitor.setName(userName)
        visitor.setEmail(email)
        ZohoSalesIQ.Chat.show()
   }
Rishabh-Raghunath commented 3 years ago

If Mobilisten is initialized at the time of invoking the ZohoSalesIQ.Chat.show() API, everything should work. Is the button using which the chat is opened made visible only after successful initialization?

I would also like to point out that the visitor information is being incorrectly set in the shared code snippet. Please set the information as shown below;

ZohoSalesIQ.Visitor.setName(userName)
ZohoSalesIQ.Visitor.setEmail(userEmail)

I would also highly suggest having Mobilisten initialized in the AppDelegate within the application(_:didFinishLaunchingWithOptions:) method. This way, ZohoSalesIQ.initWithAppKey is called only once, and not every time an instance of the view controller loads within the viewDidLoad method.

Could you try applying the above suggestions and let us know if everything works as expected?

ammarmarn commented 3 years ago

Thanks for the suggestions I will incorporate them, one thing want to ask that instead of removing initialization in viewDidLoad() I am thinking to check if SDK is initialized if not then initialize it within the check.

  override func viewDidLoad() {
    if !ZohoSalesIQ.Chat.isEnabled {
          ZohoSalesIQ.initWithAppKey
        }
   }
Rishabh-Raghunath commented 3 years ago

This would not be needed since Chat may be disabled for other reasons as well. For example, if you choose to hide the chat option when operators are offline.

Within the viewDidLoad method of a view controller, the value for ZohoSalesIQ.Chat.isEnabled alone can be checked and the chat button can then be made visible if it's true and similarly be hidden if the value is false.

ammarmarn commented 3 years ago

I have splitVC on which Support is an option that's always visible (can't hide it) and can be selected anytime/mulitple times.

Screenshot 2021-09-23 at 7 00 10 PM

And following is simple code when support selected

Screenshot 2021-09-23 at 7 01 50 PM

What do you suggest will be suitable if "ZohoSalesIQ.Chat.isEnabled" returns false. Shall I then call following. But problem is I don't know when it will return and what if user selected any other side menu option meanwhile popping up chat window later on suddenly will make bad user experience.

ZohoSalesIQ.initWithAppKey(appKey, accessKey: accessKey) { (success) in
  if success {
    ZohoSalesIQ.Chat.show()
  } }
ammarmarn commented 3 years ago

Apart from above question I got this crash: "NSInvalidArgumentException: Application tried to present modally a view controller <Mobilisten.LCNavigationController: 0x14a8f9400> that is already being presented by <Marn.BaseSlidingController: 0x14b525590>." What do you think can be the cause? (although I think this could be when user multiple tap on support button, but if I am trying to reproduce I am not getting this crash though).

Rishabh-Raghunath commented 3 years ago

I have splitVC on which Support is an option that's always visible (can't hide it) and can be selected anytime/mulitple times.

Screenshot 2021-09-23 at 7 00 10 PM

And following is simple code when support selected

Screenshot 2021-09-23 at 7 01 50 PM

What do you suggest will be suitable if "ZohoSalesIQ.Chat.isEnabled" returns false. Shall I then call following. But problem is I don't know when it will return and what if user selected any other side menu option meanwhile popping up chat window later on suddenly will make bad user experience.

ZohoSalesIQ.initWithAppKey(appKey, accessKey: accessKey) { (success) in
  if success {
    ZohoSalesIQ.Chat.show()
  } }

The value for ZohoSalesIQ.Chat.isEnabled is false when the option to open chat is not to be shown.

The value can be false in the following cases:

  1. Mobilisten is not initialized.
  2. The user is IP blocked by an operator.
  3. All departments are offline and you choose to hide chat during the time.
  4. If the current time falls outside the configured business hours and you choose to hide chat during the time.

In this case, you may display the "Support" option as disabled (greyed out) or be hidden. You may refresh the list once when the init completion closure is executed.

Rishabh-Raghunath commented 3 years ago

We hope that the API reference provided answers your question. We are closing this issue since it has had no recent activity. Please feel free to get back to us through the comments in case you have further queries. Thanks.