Take the 2-minute tour ×

I have a PhoneGap/Corodova Project for iOS. Whilst building on the iOS simulator I used Jquery Cookies and they were fine. However, now that I have the app on my device for testing, they no longer work. I'm guessing this is just something iOS doesnt support.

Does anyone know a way to do client side cookies for iOS?

PS: My current cookies code (just in case its useful):

<script type="text/javascript" charset="utf-8" src="js/jquery.cookie.js"></script>
     <script type="text/javascript">
        $(function() {
        var cookiedate = new Date();
        cookiedate.setTime(cookiedate.getTime() + (60 * 60 * 1000));
        $.cookie("startupscreen", "checked", { expires: cookiedate, path: '/' })
share|improve this question
try this settings, might work - groups.google.com/forum/?fromgroups#!topic/phonegap/ZJE1nxX63ow –  dhaval Jun 27 '12 at 6:08
I have the same problem. I'm trying to set cookies from an AJAX call though, and in PhoneGap 2.0 the NSHTTPCookieStorage setting is already in AppDelegate.m... but to no avail the iOS6 won't set the cookie from my .NET MVC3 application. –  sonjz Oct 25 '12 at 19:22

2 Answers 2

up vote 2 down vote accepted

Why not use localStorage? ios5 supports HTML5 features like localStorage.


share|improve this answer
Thanks! Thats what I ended up doing though I'm not sure if this is the best way as local storage is supposed to be discontinued by W3C –  MeltingDog Oct 25 '12 at 23:43
localStorage will not be discontinued, it's the sql database that will be discontinued. But even if the spec is removed from html5 browsers will probably continue to support it after. –  weexpectedTHIS Oct 26 '12 at 6:12
Only reason WebSQL spec isn't being developed further is that everybody accidentally standardized on embedded SQLite, so it was beside the point to push the standard further... It shouldn't be going anywhere. –  XMLilley Dec 19 '12 at 20:32

Put this here in your app delegate :

-(void)applicationDidEnterBackground:(UIApplication *)application{
    NSData *cookiesData = [NSKeyedArchiver archivedDataWithRootObject:[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]];
    [[NSUserDefaults standardUserDefaults] setObject:cookiesData


and in (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:

// Restore cookies
    NSData *cookiesData = [[NSUserDefaults standardUserDefaults] objectForKey:@"xapp"];
    if (cookiesData) {
        NSArray *cookies = [NSKeyedUnarchiver unarchiveObjectWithData:cookiesData];
        for (NSHTTPCookie *cookie in cookies)
        { [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie]; }


This made cookies working as usual in Cordova 3.4.x and ios6+

share|improve this answer
Code can be formatted by indenting by four spaces (you can select and use the {} button as a shortcut.) –  McDowell Mar 23 at 16:45

Your Answer


