如何在UIWebView

时间:2016-08-10 08:50:00

标签: ios objective-c iphone xcode uiwebview

但是,因为我通过调用UIWebView的loadRequest在UIWebView中加载网页,所以这些技术并不适用。

任何想法如何保存网页中的登录内容,以便再次启动应用程序以在UIWebView页面中保存我的登录内容,

此网址保存登录内容: - http://aubonpain.mloyalconnect.com/microsite/

2 个答案:

答案 0 :(得分:0)

document.querySelectorAll( “输入[类型= '密码']”)

对于所有textField使用:document.querySelectorAll(“input [type ='text']”)

DecryptRijndael

}

答案 1 :(得分:0)

我在我的几个实时应用程序中使用以下内容并且它们运行良好。

收到回复后保存Cookie

- (void)saveCookiesToDefaults
{
    NSData *cookiesData = [NSKeyedArchiver archivedDataWithRootObject:[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]];
    [[NSUserDefaults standardUserDefaults] setObject:cookiesData forKey:@"SAVED_COOKIES"];
}  

加载Cookie

- (void)loadCookies
{
    NSArray *cookies = [NSKeyedUnarchiver unarchiveObjectWithData: [[NSUserDefaults standardUserDefaults] objectForKey: @"SAVED_COOKIES"]];
    NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];

    for (NSHTTPCookie *cookie in cookies)
    {
        NSMutableDictionary *newProperties = [[NSMutableDictionary alloc]initWithDictionary:cookie.properties];
        NSDate *date = [newProperties objectForKey:NSHTTPCookieExpires];
        if(date == nil)
            [newProperties setObject:[[NSDate date] dateByAddingTimeInterval:100*12*30*60*60] forKey:NSHTTPCookieExpires];
        else
            [newProperties setObject:[[NSDate date] dateByAddingTimeInterval:100*12*30*60*60] forKey:NSHTTPCookieExpires];
        NSHTTPCookie *newCookie = [NSHTTPCookie cookieWithProperties:newProperties];
        [cookieStorage setCookie: newCookie];
        NSLog(@"%@",newCookie);
    }
}  

清除会话中的Cookie

- (void)clearCookies
{
    for (NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies])
    {
        [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
    }

    [[NSURLCache sharedURLCache] removeAllCachedResponses];
    NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
    [NSURLCache setSharedURLCache:sharedCache];
    [[NSUserDefaults standardUserDefaults] setObject:nil forKey:@"SAVED_COOKIES"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}  

检查会话是否存在

- (BOOL)hasExistingSession
{
    NSData *savedCookiesData = [[NSUserDefaults standardUserDefaults] objectForKey:@"SAVED_COOKIES"];
    if(savedCookiesData == nil)
        return 0;
    else
    {
        NSArray *savedCookies = [NSKeyedUnarchiver unarchiveObjectWithData:savedCookiesData];

        for (NSHTTPCookie *cookie in savedCookies)
        {
            [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
        }

        NSLog(@"HAS EXISTING SESSION: %@", savedCookies.count ? @"YES" : @"NO");

        return savedCookies.count;
    }

}