Search code examples
iphoneiosxcode4uiwebview

iPhone SDK: Different instances of webviews


in xcode, when you display facebook for example in a webview, and you sign in, opening another instance of facebook in another webview will display facebook logged in as well as if the webviews were linked. I wanted to know if there was a way to load different instances of webviews so that one is not linekd with the other in any way. Google chrome for example can do this in their application where as a regular tab and an incognito tab use different instaces of a webview. I've tried many different things but nothing has worked so far.


Solution

  • One thing you could do, perhaps, is if you didn't want the user to be logged in when they go back to the webview is clear the Cookies.

    // Clear Cookies
    NSHTTPCookie *cookie;
    NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    for (cookie in [storage cookies]) {
        [storage deleteCookie:cookie];
    }
    [[NSUserDefaults standardUserDefaults] synchronize];
    

    Put that before the WebView is loaded, and the user won't be logged in.