Set a cookie in the iOS app and read this cookie from Safari

I am trying to do the following: inside my appDelegate application, I am setting a cookie. After that, I try to read this cookie using JavaScript from webapp. Is it possible? Because I can't get it to work ...

This is my code in an iOS app:

NSMutableDictionary *cookieProperties = [NSMutableDictionary dictionary];
[cookieProperties setObject:@"test" forKey:NSHTTPCookieName];
[cookieProperties setObject:@"yes" forKey:NSHTTPCookieValue];
[cookieProperties setObject:self.siteURL forKey:NSHTTPCookieDomain];
[cookieProperties setObject:self.siteURL forKey:NSHTTPCookieOriginURL];
[cookieProperties setObject:@"/" forKey:NSHTTPCookiePath];
[cookieProperties setObject:@"0" forKey:NSHTTPCookieVersion];

[cookieProperties setObject:[[NSDate date] dateByAddingTimeInterval:9629743] forKey:NSHTTPCookieExpires];

NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:cookieProperties];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie]; 

And in my JavaScript, I use the jquery.cookie plugin to write and read cookies. But there is nothing ... This is my code:

cookieValue = $.cookie("test");
alert(cookieValue);

The warning has an “object object” in the body and should be set to “yes”, which I installed in my application.

Do you guys think this is possible?

Thank!

+5
source share
1 answer

: cookie Safari , . cookie Safari, URL- Safari cookie , script URL- cookie .

EDIT: , URL- iOS URL- -. - cookie, URL- .

+6

All Articles