Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. i have a question about how to structure my stuff. in my app, which is going to download a set of documents from a json service, i have a control sequence i'm trying to implement. It's a bit long, so i'll write it in a new line, but please let me know if i shold do anything differently.
  2.  
  3. I have an initial screen with a login prompt. I had statically written the authentication method in this, and it works, but i need a way of checking if a session is valid throughout my app, so i moved the login method to controllers/AuthenticationController.m, alongside other utility methods such as checkIfSessionIsValid.
  4.  
  5. I also created a generic document controller, DocumentController, which handles json requests in order to populate an array of Document objects, defined in classes/Document.m.
  6.  
  7. My challenge is the following:
  8. In any arbitrary view controller i need to check for a valid session before carrying out any json requests. I have set this up in my api to return a simple "valid" true/false json object if the server side session has epire. If this returns false, i need to nil the document array, user login information, and return to the login screen.
  9.  
  10. This is how i imagined implementing it, but i'm not sure if it's the way to go.
  11. 1. Have every view controller import the authentication controller
  12. 2. prompt the authentication controller [auth isSessionValid]
  13. 3. if true, carry on with the json request, if false, do a programatic segue to the login screen, and in prepareforsegue on this operation nil out all user loaded info.
  14.  
  15. Assuming this is is the way to do it, here are some of the problems i have
  16. 1. I don't have a segue from every view controller to my login screen - how can i get there without one?
  17. 2. I use ASIHTTPRequest, which does an async request, and afaik the way you handle a response is by doing soemthing like this: [request setDidFinishSelector:@selector(pareseSessionValidity:)]; I don't know how to get a return value from this (it's async btw), so the view controller can get a return value.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement