<legend id='2XCgC'><style id='2XCgC'><dir id='2XCgC'><q id='2XCgC'></q></dir></style></legend>
        <bdo id='2XCgC'></bdo><ul id='2XCgC'></ul>
    1. <i id='2XCgC'><tr id='2XCgC'><dt id='2XCgC'><q id='2XCgC'><span id='2XCgC'><b id='2XCgC'><form id='2XCgC'><ins id='2XCgC'></ins><ul id='2XCgC'></ul><sub id='2XCgC'></sub></form><legend id='2XCgC'></legend><bdo id='2XCgC'><pre id='2XCgC'><center id='2XCgC'></center></pre></bdo></b><th id='2XCgC'></th></span></q></dt></tr></i><div id='2XCgC'><tfoot id='2XCgC'></tfoot><dl id='2XCgC'><fieldset id='2XCgC'></fieldset></dl></div>
    2. <small id='2XCgC'></small><noframes id='2XCgC'>

        <tfoot id='2XCgC'></tfoot>
      1. 如何设置我的 Web 视图已加载已登录用户 -iPhone

        时间:2023-10-22
            <i id='K43sC'><tr id='K43sC'><dt id='K43sC'><q id='K43sC'><span id='K43sC'><b id='K43sC'><form id='K43sC'><ins id='K43sC'></ins><ul id='K43sC'></ul><sub id='K43sC'></sub></form><legend id='K43sC'></legend><bdo id='K43sC'><pre id='K43sC'><center id='K43sC'></center></pre></bdo></b><th id='K43sC'></th></span></q></dt></tr></i><div id='K43sC'><tfoot id='K43sC'></tfoot><dl id='K43sC'><fieldset id='K43sC'></fieldset></dl></div>

              <bdo id='K43sC'></bdo><ul id='K43sC'></ul>
              <legend id='K43sC'><style id='K43sC'><dir id='K43sC'><q id='K43sC'></q></dir></style></legend>
                <tbody id='K43sC'></tbody>

            • <tfoot id='K43sC'></tfoot>

              <small id='K43sC'></small><noframes id='K43sC'>

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

                  问题描述

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

                  • 当我点击主页/主页中的按钮时,该网页视图已加载

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

                  • 然后加载 web 视图,我在邮件视图中使用了这样的代码:

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

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

                  我想要的是,

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

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

                  • 如果我还没有登录,请在登录时显示警报.

                  怎么做?

                  请帮助我.提前致谢.

                  解决方案

                  首先,我认为你应该加载的 URL 是 http://mail.google.com/mailp>

                  除此之外,由于 UIWebView 不会在应用程序运行之间保存 cookie,因此您没有获得正常的 gmail 行为,您应该尝试这样的方法来保存它们:

                  - (void)saveCookies{NSData *cookiesData = [NSKeyedArchiver archivedDataWithRootObject: [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]];NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];[默认设置对象:cookiesData forKey:@cookies"];[默认同步];}

                  并使用以下方法将它们加载回来:

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

                  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];
                    }
                    

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

                  What i want is,

                  • 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.

                  How to do it?

                  Please help me. Thanks in advance.

                  解决方案

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

                  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];
                  }
                  

                  and load them back using this:

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

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

                  上一篇:重用的 UIWebView 在 iPhone 上短暂显示之前加载的内容 下一篇:根据其内容计算 UIWebView 高度

                  相关文章

                    <bdo id='AtjGq'></bdo><ul id='AtjGq'></ul>

                      <small id='AtjGq'></small><noframes id='AtjGq'>

                    1. <tfoot id='AtjGq'></tfoot>
                      <legend id='AtjGq'><style id='AtjGq'><dir id='AtjGq'><q id='AtjGq'></q></dir></style></legend>
                    2. <i id='AtjGq'><tr id='AtjGq'><dt id='AtjGq'><q id='AtjGq'><span id='AtjGq'><b id='AtjGq'><form id='AtjGq'><ins id='AtjGq'></ins><ul id='AtjGq'></ul><sub id='AtjGq'></sub></form><legend id='AtjGq'></legend><bdo id='AtjGq'><pre id='AtjGq'><center id='AtjGq'></center></pre></bdo></b><th id='AtjGq'></th></span></q></dt></tr></i><div id='AtjGq'><tfoot id='AtjGq'></tfoot><dl id='AtjGq'><fieldset id='AtjGq'></fieldset></dl></div>