Where cookie is managed in phonegap app with jquery?

后端 未结 1 1962
生来不讨喜
生来不讨喜 2021-01-30 18:46

My native iphone app, developed with phonegap with jquery (so its browser based), can log in to web server and once logged in users can access their resources. The server sets s

相关标签:
1条回答
  • 2021-01-30 19:30

    If you want your app to automatically manage cookies for you add this to your appDelegate.m file:

    NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage 
                                          sharedHTTPCookieStorage]; 
    [cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways]; 
    

    If you want to manage the session information by yourself, you can do all ajax requests like this:

    var request =   {
                    url: my_server_url,
                    success: function(response, status, request) {
                        var header = request.getAllResponseHeaders();
                        var match = header.match(/(Set-Cookie|set-cookie): (.+?);/);
                        if(match)
                            my_saved_cookie = match[2];
                    },
                    }
    
    if(my_saved_cookie)
        request.headers = { Cookie: my_saved_cookie };
    
    $.ajax(request);
    

    In my app I was managing the session cookies by myself using the second method until I discovered the first method.

    0 讨论(0)
提交回复
热议问题