Swift-Application with Login and offlinemodus

2019-09-14 19:06发布

问题:

maybe this is for many of you a very simple question but I need some tipps.

I will create a app, which can be used online and offline. At the webserver is symfony with the FOSUserBundle used. Login and working in the webbrowser works very well.

My aim is:

Start the app on a iOS-Device. When the user are not be logged in, then the loginform from the application would be viewed. The login should be able to remember.

The app will after the login synchronize the data from the webserver with the device-database.

When the user didn't have a mobileconnection and he didn't log himself out, then the application should show the screen with his data. I mean this like the messenger from facebook.

All views on the mobiledevice are completely developed with swift. There is not a webview from the webserver.

Please can you give me for this a little tip, for what I have to search?

I search for FOSOAuthServerBundle but I dont think that I am on the right way.

回答1:

What I did for my app with symfony as a backend:

  • having a controller in symfony which receives the login data from the app and check if the username and password are correct. After this confirmation, the controller is answering with the data I need in the app (json format)

  • in the app I save the username and password (I need this because if there is no connection to the internet I need to check the login against something).

It means, that every time the user logged in successful with internet connection, the username and password are saved.

  • in the app I save the json-response with key-archiving into documents folder.

  • the app always loads the json-file from documents folder, after the user logged in successfully.

So with internet connection:

1) check username and password against the FOSUserbundle in Symfony

2) save the username and password in the app

3) save the response as file into documents folder

4) let the app load its content from that folder

Without internet connection

1) check username and password against the credentials stored in the app from the last successful login with internet connection

2) let the app load its content from the documents folder