如何使用已登录用户-iPhone设置我的Web视图 [英] How to set my web view loaded with already login user -iPhone

查看:220
本文介绍了如何使用已登录用户-iPhone设置我的Web视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中使用带URL的Web视图:@http://www.gmail.com/。

In my app iam using web view with URL:@"http://www.gmail.com/".


  • 当我点击主页/主页中的按钮时加载了这个网页视图

  • This web view was loaded when i clicked a button in the main page / home page

(IBAction)webClick:(id)sender
 {
MailViewController *mail = [[MailViewController alloc]initWithNibName:@"MailViewController" bundle:nil];
[self.navigationController pushViewController:mail animated:YES];
}


  • 然后加载了网页视图,我使用的代码很像这个在邮件视图中:

  • Then the web view was loaded, i used code like thin this in mail view:

    -(void)viewDidLoad
    
    {
        [super viewDidLoad];
        NSString *urlAddress = @"http://www.gmail.com/";
        NSURL *url = [NSURL URLWithString:urlAddress];
        NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
        [webView loadRequest:requestObj];
    }
    


  • 这里打开了gmail登录页面。我们需要输入用户名&密码。

    Here the gmail opened with login page. we need to enter username & password.

    我想要的是,


    • 如果我们已经通过gmail应用程序登录我的帐户..

    • if we already login into my account through gmail application..

    加载的视图直接挂载我的邮件,而不是登录页面。

    The loaded view directly loades my mail, instead of login page.

    如果我还没有进入,请在登录时显示提醒。

    if i didn't already loged in, then show an alert as please login.

    如何这样做?

    请帮帮我。
    提前致谢。

    Please help me. Thanks in advance.

    推荐答案

    首先,我认为您应该加载的网址是 http://mail.google.com/mail

    First of all, I think the URL you should be loading is http://mail.google.com/mail

    除此之外,你没有获得正常的gmail行为,因为UIWebView确实如此不保存应用程序运行之间的cookie,你应该尝试这样的东西来保存它们:

    Other than that, you're not getting normal gmail behavior because UIWebView does not save cookies between app runs, you should try something like this to save them:

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

    并使用此加载它们:

    - (void)loadCookies
    {
        NSArray             *cookies       = [NSKeyedUnarchiver unarchiveObjectWithData: [[NSUserDefaults standardUserDefaults] objectForKey: @"cookies"]];
        NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    
        for (NSHTTPCookie *cookie in cookies)
        {
            [cookieStorage setCookie: cookie];
        }
    }
    

    这篇关于如何使用已登录用户-iPhone设置我的Web视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆