Created
January 21, 2011 00:20
-
-
Save jxson/789006 to your computer and use it in GitHub Desktop.
Enable Cookies in your phoneGap app and open http/ https links in safari
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (id) init | |
{ | |
/** | |
* Enable cookies | |
**/ | |
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; | |
[cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways]; | |
NSHTTPCookie *cookie; | |
for (cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] | |
cookies]) { | |
NSLog(@"%@", [cookie description]); | |
} | |
return [super init]; | |
} | |
- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType | |
{ | |
NSURL *url = [request URL]; | |
if ([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) | |
{ | |
[[UIApplication sharedApplication] openURL:url]; | |
return NO; | |
} | |
else | |
{ | |
return [ super webView:theWebView | |
shouldStartLoadWithRequest:request | |
navigationType:navigationType ]; | |
} | |
} |
hey @bringo, this was an old snippet. I have not tried getting cookies working in a webview in iOS5 and the code above was kind of a hack to get cookies to work the way I wanted in the phone gap project.
Thanks for letting me know. Looks like they added this to PhoneGap directly... not that it is actually doing what it is supposed to for my app. :(
https://github.com/callback/callback-ios/blob/master/PhoneGapLib/Classes/PhoneGapDelegate.m#L64
I know your pain, good luck with your app!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It looks like NSHTTPCookieAcceptPolicyAlways is the default policy in iOS5. Setting this doesn't seem to have the intended effect for me. My app still doesn't seem to be able to store cookies. Any ideas what else can be done?