could not set cookie in iPhone

693 views
Skip to first unread message

WentingLiu

unread,
Jul 13, 2010, 9:50:16 PM7/13/10
to phonegap
works fine on Symbian, but not work on iPhone .
I added these codes too my project according to this Post,http://
groups.google.com/group/phonegap/browse_thread/thread/f2fb7ecfa47e6a3c/
551dc45453acc8ed?hl=en&lnk=gst&q=xmlhttp+cookies#551dc45453acc8ed.
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage
sharedHTTPCookieStorage];
[cookieStorage
setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];


But it still don't work .Could anyone help? Tks!

Giacomo Balli

unread,
Jul 14, 2010, 1:50:42 PM7/14/10
to phonegap
cookies are old school... use localStorage!

Jesse MacFadyen

unread,
Jul 14, 2010, 3:46:10 PM7/14/10
to Giacomo Balli, phonegap
To enable cookies in your iPhone PhoneGap application, add the following code to your applicationDidFinishLaunching.  You can do this on a project by project basis, this will likely not be added to PhoneGap directly.

- (void)applicationDidFinishLaunching:(UIApplication *)application
{

NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; 
[ cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways]; 
[ super applicationDidFinishLaunching:application ];

}

Yeah, cookies are old-school, but it makes things so much easier for the server.  If you are interacting with the server via XHR, the server can use your cookie to store a sessionID after login, and all future XHR requests will not require that you send your credentials around.  

I have not tried modifying or setting cookies from JavaScript, just from the server.  For storing information for use within your application JavaScript, localStorage or sessionStorage, or SQLite, or LawnChair are the way to go.

Cheers,
  Jesse



--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en

For more info on PhoneGap or to download the code go to www.phonegap.com



--
--
Jesse MacFadyen
{
  blog:'blogs.nitobi.com/jesse',
  email:'jesse.m...@nitobi.com',
  company:
  {
    name:'Nitobi Software',
    site:'www.nitobi.com',
    phone:
    {
      office:'+1 (604) 685-9287',
      tollFree:'1-866-632-2777'
     }
  }
}

Mayank

unread,
Jul 23, 2010, 9:51:46 PM7/23/10
to phonegap
Yup, it does work when server sets the cookie. Has anyone tried
setting cookies through javascript ? It looks like it doesn't work
atleast on iphone. Maybe because iphone app only exposes
NSHTTPCookieStorage object that manages cookies, while javascript
tries to set them via document.cookie. Any ideas anyone ??

-Mayank

On Jul 14, 12:46 pm, Jesse MacFadyen <jesse.macfad...@nitobi.com>
wrote:
> To enable cookies in your iPhone PhoneGap application, add the following
> code to your applicationDidFinishLaunching.  You can do this on a project by
> project basis, this will likely not be added to PhoneGap directly.
>
> - (void)applicationDidFinishLaunching:(UIApplication *)application
> {
>
> NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage
> sharedHTTPCookieStorage];
> [ cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
> [ super applicationDidFinishLaunching:application ];
>
> }
>
> Yeah, cookies are old-school, but it makes things so much easier for the
> server.  If you are interacting with the server via XHR, the server can use
> your cookie to store a sessionID after login, and all future XHR requests
> will not require that you send your credentials around.
>
> I have not tried modifying or setting cookies from JavaScript, just from the
> server.  For storing information for use within your application JavaScript,
> localStorage or sessionStorage, or SQLite, or LawnChair are the way to go.
>
> Cheers,
>   Jesse
>
> On Wed, Jul 14, 2010 at 10:50 AM, Giacomo Balli <giacomoba...@gmail.com>wrote:
>
>
>
> > cookies are old school... use localStorage!
>
> > On Jul 14, 3:50 am, WentingLiu <durianol...@gmail.com> wrote:
> > > works fine on Symbian, but not work on iPhone .
> > > I added these codes too my project according to this Post,http://
> > > groups.google.com/group/phonegap/browse_thread/thread/f2fb7ecfa47e6a3c/
> > > 551dc45453acc8ed?hl=en&lnk=gst&q=xmlhttp+cookies#551dc45453acc8ed.
> > >   NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage
> > > sharedHTTPCookieStorage];
> > >  [cookieStorage
> > > setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
>
> > > But it still don't work .Could anyone help? Tks!
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "phonegap" group.
> > To post to this group, send email to phon...@googlegroups.com
> > To unsubscribe from this group, send email to
> > phonegap+u...@googlegroups.com<phonegap%2Bunsu...@googlegroups.com>
> > For more options, visit this group at
> >http://groups.google.com/group/phonegap?hl=en?hl=en
>
> > For more info on PhoneGap or to download the code go towww.phonegap.com
>
> --
> --
> Jesse MacFadyen
> {
>   blog:'blogs.nitobi.com/jesse',
>   email:'jesse.macfad...@nitobi.com <email%3A%27jesse.macfad...@nitobi.com>
Reply all
Reply to author
Forward
0 new messages