Iphone UIWebview不获取Cookie
我的UIWebview根本不保存cookies。它被困在无cookie模式,因此,网页将cookie信息放在url中 这就是我正在做的。我的UIWebview有一个单例,底部有4个UITabBar按钮。每个选项卡栏按钮都会将用户带到站点上的不同页面。现在,当用户通过webview本身导航站点时,一切正常,会话持续。但是,当用户单击tabbar按钮时,会话就会重置 我甚至将NSHTTPookieStorage设置为始终接受cookies。还是不行 以下是我的UIWebview和NSMutableUrlRequest单例的代码Iphone UIWebview不获取Cookie,iphone,ios,cookies,uiwebview,xamarin.ios,Iphone,Ios,Cookies,Uiwebview,Xamarin.ios,我的UIWebview根本不保存cookies。它被困在无cookie模式,因此,网页将cookie信息放在url中 这就是我正在做的。我的UIWebview有一个单例,底部有4个UITabBar按钮。每个选项卡栏按钮都会将用户带到站点上的不同页面。现在,当用户通过webview本身导航站点时,一切正常,会话持续。但是,当用户单击tabbar按钮时,会话就会重置 我甚至将NSHTTPookieStorage设置为始终接受cookies。还是不行 以下是我的UIWebview和NSMutableU
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不接受cookies吗?我仍然对NSHTTPookie存储以及我是否正确使用了它感到困惑
非常感谢。我做了这项工作,这已经足够了
因为cookie在url中,所以我只需解析它,并通过编程将其放入tabbar按钮指向的url中。问题已解决。它们是持久cookie,而不是会话cookie吗?我可以在chrome中查看,并正确获取cookie。