quest
quest

Reputation: 776

Cookies/State of Cocoa WebView not being preserved

Having a few issues with my current build of PandoraMan (http://github.com/zquestz/PandoraMan). Everything is functional for the most part, window position is being saved, all essential functionality works, however I am seeing one bug.

When I login to Pandora, it never gets preserved. I was under the assumption that it read the system cookies and shared state with Safari. The older version (using an ancient xcode on 10.4) worked fine.

If I launch the app and login using PandoraMan, it logs in, and the site works as normal. However when I restart the app I always have to login again. This never used to happen, and I can't find anything in the docs regarding this issue.

If anyone has some insight on this issue it would be fantastic. The code is open source, so you can check out the issue without bouncing code back and forth in the comments.

Upvotes: 5

Views: 2641

Answers (2)

Vojto
Vojto

Reputation: 6959

Pandora uses localStorage to preserve user state. Use this:

WebPreferences* prefs = [WebPreferences standardPreferences];
[prefs _setLocalStorageDatabasePath:@"~/Library/Application Support/MyApp"];
[prefs setLocalStorageEnabled:YES];
[self.webView setPreferences:prefs];

Add these to the beginning of the file:

@interface WebPreferences (WebPreferencesPrivate)
- (void)_setLocalStorageDatabasePath:(NSString *)path;
- (void)setLocalStorageEnabled:(BOOL)localStorageEnabled;
@end

More: How do I enable Local Storage in my WebKit-based application?

Upvotes: 1

Ajeet Pratap Maurya
Ajeet Pratap Maurya

Reputation: 4254

Your application has its own "cookie jar" in the [NSHTTPCookieStorage sharedHTTPCookieStorage] container.

Here's how you might take a quick look at the cookies in your application's cookie jar:

NSHTTPCookie *cookie;
NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [cookieJar cookies]) {
    NSLog(@"%@", cookie);
}

Several methods are available for filtering and manipulation. Take a look at the NSHTTPCookieStorage documentation for accessing cookies, and the NSHTTPCookie documentation for accessing individual cookie properties

May be this can help your problem.

Upvotes: 1

Related Questions