iosswiftdelegatessmartfoxserver

iOS delegate method in framework


We are implementing a iOS framework which will be used by third-party developers. This framework need to provide few screens for user login(LoginView) and profile. Framework has a Helper class where it interacts with server APIs, e.g connect(), onConnection() and here onConnection() is callback method using delegate.

The third-party application is adding our framework and using LoginView as initial screen.

When connect(), onConnection() are part of LoginView, everything is working fine.

Where as, if connect(), onConnection() are part of Helper class, OnConnection() callback is not getting called.

This could be solved by implementing proper way of delegation, I tried using making Helper class as delegator of LoginView. But it is not working.

Can somebody help us?


Solution

  • Try the following: Edited my previous answer to the suggestion given

    1. Make the Delegate Class like YourAuthenticationManaged and implement the protocols that are @optional and @required.
    2. Make the AuthManager class for the Delegate to be invoked inside and respond to selected by using perform selector. Example [_delegate performselector(@selector:connectionestablished:)] in this AuthManager.
    3. Expose the delegate as property for the AuthManager.
    4. Prefer the AuthManager to be a singleton class.
    5. Now anywhere in your view controller or base view controller Allocate and assign the Authmanager delegate property to the view controller class.
    6. Observe the delegates in the implementation class in the View controller.
    7. Once you give a calls like connect, disconnect put NSLogs in the overidden delegates inside view controller.
    8. This should get triggered and observed once the perform action is invoked in the AuthManager.

    If any issues please comment shall be happy to help. Enjoy coding.