admin管理员组文章数量:1025761
I'm trying to do the following: Inside my appDelegate I'm setting a cookie. After that I'm trying to read that cookie using JavaScript from a webapp. Is this possible? Because I can't make it work...
This is my code in the 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'm using the jquery.cookie plugin for writing and reading cookies. But nothing is there... This is my code:
cookieValue = $.cookie("test");
alert(cookieValue);
The alert has in the body "[object Object]" and there should be the "yes" value I set in my app.
Do you guys think this is possible?
Thanks!
I'm trying to do the following: Inside my appDelegate I'm setting a cookie. After that I'm trying to read that cookie using JavaScript from a webapp. Is this possible? Because I can't make it work...
This is my code in the 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'm using the jquery.cookie plugin for writing and reading cookies. But nothing is there... This is my code:
cookieValue = $.cookie("test");
alert(cookieValue);
The alert has in the body "[object Object]" and there should be the "yes" value I set in my app.
Do you guys think this is possible?
Thanks!
Share Improve this question asked Apr 23, 2013 at 18:54 AndresAndres 11.8k13 gold badges54 silver badges90 bronze badges1 Answer
Reset to default 6Not possible: the global Safari cookie cache isn't accessible to third-party applications, as that would be a significant security hole. If you need to send cookie information to Safari you'd be better served launching a URL into Safari with the cookie details as request parameters and then having the script at the end of that URL create the cookies and send them back.
EDIT: If you want to be slick you can register a URL handler for your iOS app and then launch the URL to your web app. Have your web app set the cookies, then redirect back to the app URL.
I'm trying to do the following: Inside my appDelegate I'm setting a cookie. After that I'm trying to read that cookie using JavaScript from a webapp. Is this possible? Because I can't make it work...
This is my code in the 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'm using the jquery.cookie plugin for writing and reading cookies. But nothing is there... This is my code:
cookieValue = $.cookie("test");
alert(cookieValue);
The alert has in the body "[object Object]" and there should be the "yes" value I set in my app.
Do you guys think this is possible?
Thanks!
I'm trying to do the following: Inside my appDelegate I'm setting a cookie. After that I'm trying to read that cookie using JavaScript from a webapp. Is this possible? Because I can't make it work...
This is my code in the 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'm using the jquery.cookie plugin for writing and reading cookies. But nothing is there... This is my code:
cookieValue = $.cookie("test");
alert(cookieValue);
The alert has in the body "[object Object]" and there should be the "yes" value I set in my app.
Do you guys think this is possible?
Thanks!
Share Improve this question asked Apr 23, 2013 at 18:54 AndresAndres 11.8k13 gold badges54 silver badges90 bronze badges1 Answer
Reset to default 6Not possible: the global Safari cookie cache isn't accessible to third-party applications, as that would be a significant security hole. If you need to send cookie information to Safari you'd be better served launching a URL into Safari with the cookie details as request parameters and then having the script at the end of that URL create the cookies and send them back.
EDIT: If you want to be slick you can register a URL handler for your iOS app and then launch the URL to your web app. Have your web app set the cookies, then redirect back to the app URL.
本文标签: javascriptSet a cookie in a iOS app and read that cookie from SafariStack Overflow
版权声明:本文标题:javascript - Set a cookie in a iOS app and read that cookie from Safari - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745639729a2160669.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论