Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9221363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:33:49+00:00 2026-06-18T03:33:49+00:00

In my iPhone app, I am using AFNetworking to make HTTP requests to a

  • 0

In my iPhone app, I am using AFNetworking to make HTTP requests to a PHP API.

Every time I open the app, I have to login and the server will initiate the sessions.
After I log in, every time I will make an HTTP request to the API, the API knows that I have the session and will allow me to use every function of the API.

The problem is that after I close the app, I think that the sessions are destroyed and I am can’t use any functionality from the API without having to login again.

I am talking about an iPhone app here which uses AFNetworking to make the HTTP request.
From my tests I know that the session is destroyed after the app is closed.

I want to know if this is true and I want to know what’s the best way of making an authentication system. I think that session is not a solution anymore, since they are destroyed after the app is closed. My alternative was to create an auth_token every time someone logs in and store the token in the app, then every time someone open the app the first http request they will make it will contain the auth_token and if that token matches with the one from the database, then initialize the session as usual. I think that this can be a bit slower, providing that every time you open the app it will have to make an HTTPS request to initialize the connection between the client and the server.

So the question is: Is it true that you can keep the session alive after you close the app? Is it my alternative a good one?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:33:50+00:00Added an answer on June 18, 2026 at 3:33 am

    This is the solution to my question.
    If you are using AFNetworking the cookies are removed after you close the app. So to fix this you can save the cookies in user defaults and then load them when the app is open.

    Save the cookies (you should check the name of the cookie first, mine was PHPSESSID, because you don’t want to save unuseful cookies):

        NSArray * all = [NSHTTPCookie cookiesWithResponseHeaderFields:[self.response allHeaderFields] forURL:[NSURL URLWithString:@"http://link.to.api" ]];
        for (NSHTTPCookie *cookie in all)
        {
            if([cookie.name compare:@"PHPSESSID"] == NSOrderedSame)
            {
                NSData *data = [NSKeyedArchiver archivedDataWithRootObject:cookie];
                [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"MySavedCookies"];
                [[NSUserDefaults standardUserDefaults] synchronize];
            }
        }
    

    Then when you load the app in “application didFinishLaunchingWithOptions” for example:

      NSData *cookiesdata = [[NSUserDefaults standardUserDefaults] objectForKey:@"MySavedCookies"];
      if([cookiesdata length])
      {
         NSHTTPCookie *cookie = [NSKeyedUnarchiver unarchiveObjectWithData:cookiesdata];
        [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an iphone app using ASIHttpRequest. The server code is on heroku in
Here I am creating an iPhone app using facebook api. I have loaded the
I have an iPhone app using a UINavigationController. On the fourth controller of the
I am working on an iPhone mobile web app using jqtouch to make it
I have a Box2d iphone app (using cocos2d) that has a mouse joint in
I have developed an iPhone app using an iPhone 3G. How can I test
I've started programming an iPhone app using CoreData and trying to make my codebase
I am working on an iPhone app using a SQLite db. I have some
In my iPhone app using Browser I want to open a url for processing
I am creating an iphone app using Facebook api. Here I'm using the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.