大佬教程收集整理的这篇文章主要介绍了ios – 是否接受UIWebView中的Cookie?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
1:我在iPhone App中使用UIWebViews.我不知道用户可以在新闻中添加评论.但是,要评论他们必须登录.
如果没有,我如何在UIWebViews中接受cookies?
2:UIWebView中创建的Cookie是否可以在其他视图中的其他UIWebView中使用?
例如:我有我的LoginViewController,嵌入式UIWebView,我的用户可以登录/注销.如果他们在此视图中登录,该Cookie将仍然可以在CommentViewController中使用?
如果没有,我该如何做到这一点?
提前致谢 !
将以下代码放在AppDelegate类中:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //Other exisTing code [self loadhttpCookies]; return YES; } - (void)applicationDidEnterBACkground:(UIApplication *)application { //Other exisTing code [self savehttpCookies]; } - (void)applicationWillEnterForeground:(UIApplication *)application { [self loadhttpCookies]; } - (void)applicationWillTerminate:(UIApplication *)application { //Other exisTing code [self savehttpCookies]; } -(void)loadhttpCookies { NSMutableArray* cookieDictionary = [[NSUserDefaults standardUserDefaults] valueForKey:@"cookieArray"]; for (int i=0; i < cookieDictionary.count; i++) { NSMutableDictionary* cookieDictionary1 = [[NSUserDefaults standardUserDefaults] valueForKey:[cookieDictionary objectATindex:i]]; NShttpCookie *cookie = [NShttpCookie cookieWithProperties:cookieDictionary1]; [[NShttpCookieStorage sharedhttpCookieStorage] setCookie:cookie]; } } -(void)savehttpCookies { NSMutableArray *cookieArray = [[NSMutableArray alloc] init]; for (NShttpCookie *cookie in [[NShttpCookieStorage sharedhttpCookieStorage] cookies]) { [cookieArray addObject:cookie.name]; NSMutableDictionary *cookieProperties = [NSMutableDictionary Dictionary]; [cookieProperties setObject:cookie.name forKey:NShttpCookiename]; [cookieProperties setObject:cookie.value forKey:NShttpCookieValue]; [cookieProperties setObject:cookie.domain forKey:NShttpCookieDomain]; [cookieProperties setObject:cookie.path forKey:NShttpCookiePath]; [cookieProperties setObject:[NSnumber numberWithUnsignedInteger:cookie.version] forKey:NShttpCookieVersion]; [cookieProperties setObject:[[NSDate date] dateByAddingTimeInterval:2629743] forKey:NShttpCookieExpires]; [[NSUserDefaults standardUserDefaults] SETVALue:cookieProperties forKey:cookie.name]; [[NSUserDefaults standardUserDefaults] synchronize]; } [[NSUserDefaults standardUserDefaults] SETVALue:cookieArray forKey:@"cookieArray"]; [[NSUserDefaults standardUserDefaults] synchronize]; }
以上是大佬教程为你收集整理的ios – 是否接受UIWebView中的Cookie?全部内容,希望文章能够帮你解决ios – 是否接受UIWebView中的Cookie?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。