ios - UIApplication sharedApplication 在返回应用程序并重新启动时继续执行

标签 ios uiapplicationdelegate

下面的代码工作正常,但是当我回到我的应用程序时,它继续执行下面的代码,但我不知道为什么以及如何停止它。 我认为这只发生在 ios5.0 中: 应用流程 - rootviewcontroller -> mainviewcontroller ->webview

下面的代码在mainviewcontroller的webview的shouldstartloadrequest方法中调用

@property (readwrite, retain) UIWebView *_loginWebView;
...
..
- (void)viewDidLoad
{
    [super viewDidLoad];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [_loginWebView loadRequest:requestObj];
}

//每当 webview 收到打开 url 的请求时调用以下内容

   - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
            //return no is a special case there is more code in the method which I am not showing here
           if ([[UIApplication sharedApplication] canOpenURL:myURL]) 
           {
                  [[UIApplication sharedApplication] openURL:myURL];
           }
           else
           {
                  [[UIApplication sharedApplication] openURL:[NSURL URLWithString:newPath]];
           }
           return NO;
     }
     //above is a special case

}

head标签内容-

<head>
<meta name="viewport" content="width=device-width,initial-scale=1" />
  <!-- iOS Stuff -->
  <link rel="apple-touch-icon" href="images/...."/>
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <link rel="shortcut icon" href="favicon.ico" />
  <script async="async" src="https://......."></script>
  <script type="text/javascript">
..........
  </script>
</head>

最佳答案

myURL 是否在 header 中设置了元刷新?如果网页正在重新加载,将调用此方法。如果有重定向,它也会被调用。

关于ios - UIApplication sharedApplication 在返回应用程序并重新启动时继续执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14342480/

相关文章:

ios - 为什么加了super.viewdidload()程序没有进入死循环?

ios - 在 iOS 8 的 UISplitViewController 中动画显示/隐藏主视图

ios - 用 Facebook 相册填充 UITableView |操作系统

ios - 如何在 iOS 10 Swift 3 中初始化 NSFetchedResultsController

ios - 在 applicationWillEnterForeground 之前更改 View

ios - 找不到 AppDelegate 类

ios - 导入 AppDelegate

iphone - iOS从NSString中删除前N个单词

iphone - Facebook SDK 集成 - 使用 View Controller 而不是应用程序委托(delegate)

iOS - 在设备设置中,如果我更改时间,即使在应用程序后台、终止状态下也应该收到通知