2012-05-01 85 views
0

我的UIWebview根本没有保存饼干。它被卡在无Cookie模式,因此,网页将Cookie信息放入网址中。UIWebview没有得到饼干

这是我在做什么。我的UIWebview和底部有4个UITabBar按钮。每个标签栏按钮都会将用户带到网站上的其他页面。现在,当用户通过webview浏览本网站时,一切都很好,会话仍然存在。但第二个用户点击一个tabbar按钮,会话被重置。

我甚至将NSHttpCookieStorage设置为始终接受cookie。仍然没有去。

这里是我的单身的一个UIWebView和NSMutableUrlRequest

public static UIWebView instance; 
    public static NSMutableUrlRequest urlRequest; 
    public static NSUrlConnection connection; 
    public static NSHttpCookieStorage cookie; 
    static bool TokenSent = false; 
    public UIWebViewSingleton() {} 

    public static UIWebView Instance 
    { 
     get 
     { 
      if (instance == null) 
      { 
       Debugger.Debug ("new uiwebview created"); 
       cookie = NSHttpCookieStorage.SharedStorage; 
       cookie.AcceptPolicy = NSHttpCookieAcceptPolicy.Always; 
       connection = new NSUrlConnection(); 
       instance = new UIWebView(new RectangleF(0f, 0f, 320f, 416f)); 
       instance.ScalesPageToFit = true; 
       instance.LoadStarted += delegate { 
        UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true; 
       }; 
       instance.LoadFinished += delegate { 
        UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; 
        AcquireUserId(); 
       }; 
       instance.MultipleTouchEnabled = false; 
      } 
      return instance; 
     } 
    } 

    public static NSMutableUrlRequest UrlRequest 
    { 
     get 
     { 
      if (urlRequest == null) 
      { 
       urlRequest = new NSMutableUrlRequest(); 
      } 
      return urlRequest; 
     } 
    } 

代码这是我如何更改为基于页面按下哪个按钮上。后退按钮工作正常。

 case BTN_BACK: 
      btn_ret.TouchUpInside += delegate(object sender, EventArgs e) { 
       UIWebViewSingleton.Instance.GoBack();  
      }; 
      break; 

     case BTN_GUIDE: 
      btn_ret.TouchUpInside += delegate(object sender, EventArgs e) { 
       UIWebViewSingleton.UrlRequest.Url = new NSUrl(StaticFileNames.GuideUrl); 
       UIWebViewSingleton.Instance.LoadRequest (UIWebViewSingleton.UrlRequest);   
      }; 
      break; 

     case BTN_HOME: 
      btn_ret.TouchUpInside += delegate(object sender, EventArgs e) { 
       UIWebViewSingleton.UrlRequest.Url = new NSUrl(StaticFileNames.BaseUrl); 
       UIWebViewSingleton.Instance.LoadRequest (UIWebViewSingleton.UrlRequest);   
      }; 
      break; 

有没有人有任何想法,为什么我的UIWebView不接受cookie?我仍然对NSHttpCookieStorage感到困惑,如果我正确使用它。

非常感谢。

+0

它们是持久性cookie而不是会话cookie? – Gruntcakes

+0

我可以在铬合金中检查出来,并且正确得到了饼干。 – apexdodge

回答

0

我用这种解决方法就足够了。

由于cookie是在url中,我只是解析出来,并以编程方式将它放入tabbar按钮指向的url。问题解决了。