How to remain logged in until user decides to logout?

前端 未结 2 1451
野的像风
野的像风 2021-01-29 02:57

I am designing an app that it uses the web service like posting links and pictures. The first view controller checks the default username and password of the user and if it is c

相关标签:
2条回答
  • 2021-01-29 03:13

    RestKit is designed to consume APIs. Usually APIs are stateless, meaning that there is no such thing as state between requests. On traditional websites state is achieved by transmitting cookies back and forth between client and server. Apparently RestKit does not handle cookies (which is good in my opinion). From the top of my head I can think of two solutions:

    • Apparently RestKit does not handle cookies automatically. Thus, you could get the cookie after the login and attach it to every subsequent request.
    • Better: use OAuth2, which is basically a token that the user receives when logging in. This token is then appended as a parameter to each request.

    Both methods are basically the same. You have to send a token that identifies the user as logged in.

    0 讨论(0)
  • 2021-01-29 03:22

    If I understand well your situation, you have many viewcontrollers that act separately and independently. Doing so you need as many logins as the number of viewcontrollers your app manages.

    If this is your scenario, you can try to create a single class that does the login work and use your other viewcontrollers just to handle GUI.

    This will be your architecture:

    App other classes and viewcontrollers -> LOGINMANAGER -> viewcontroller 1 (pictures), viewcontroller 2 (links), viewcontroller 3 (preferences), viewcontroller 4 (whatever)...

    0 讨论(0)
提交回复
热议问题