【问题标题】:Worklight 6.2 web view not opening first time in iOSWorklight 6.2 Web 视图未在 iOS 中首次打开
【发布时间】:2014-07-31 06:44:39
【问题描述】:

我创建了一个继承为 CDVViewController 的 ViewController。现在,当我尝试启动 viewController 时,它会自动将其关闭。然后我再次启动相同的 viewController,然后它工作正常。任何人都可以让我知道为什么会发生这种情况或相同的修复方法。 工作灯版本:6.2 iOS:7.1 苹果手机:5s

AppDelegate

//
//  MyAppDelegate.h
//
//

#import "WLAppDelegate.h"
#import "WL.h"

@interface MyAppDelegate : WLAppDelegate <WLInitWebFrameworkDelegate> {

@end

//
//  MyAppDelegate.m
//

#import "AppDelegate.h"
#import "WLWebFrameworkInitResult.h"
#import "Cordova/CDVViewController.h"

@implementation Compatibility50ViewController
/**
 In iOS 5 and earlier, the UIViewController class displays views in portrait mode only. To support additional orientations, you must override the shouldAutorotateToInterfaceOrientation: method and return YES for any orientations your subclass supports.
 */
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}
@end

@implementation MyAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    BOOL result = [super application:application didFinishLaunchingWithOptions:launchOptions];
    [[WL sharedInstance] showSplashScreen];    
    [[WL sharedInstance] initializeWebFrameworkWithDelegate:self];
  // Launched the ViewContorller Here
    return result;
}

// This method is called after the WL web framework initialization is complete and web resources are ready to be used.
-(void)wlInitWebFrameworkDidCompleteWithResult:(WLWebFrameworkInitResult *)result {
    if ([result statusCode] == WLWebFrameworkInitResultSuccess) {
        [self wlInitDidCompleteSuccessfully];
    } else {
        [self wlInitDidFailWithResult:result];
    }
}

-(void)wlInitDidCompleteSuccessfully {
[[WL sharedInstance] hideSplashScreen];
}

-(void)wlInitDidFailWithResult:(WLWebFrameworkInitResult *)result
{
}

@end

// 视图控制器

#import "MainViewController.h"
#import "WL.h"

@interface KHybridBaseViewController : CDVViewController<UIWebViewDelegate>

@end

#import "KHybridBaseViewController.h"

@implementation KHybridBaseViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  if (self) {
    // Custom initialization
        self.wwwFolderName = @"www/default";
    self.startPage = [NSString stringWithFormat:@"%@",[[WL sharedInstance] mainHtmlFilePath]];

  }
  return self;
}

- (void)viewDidLoad {
  [super viewDidLoad];
  // Do any additional setup after loading the view from its nib.

}

- (void) viewWillAppear:(BOOL)animated {

}

- (void)didReceiveMemoryWarning {
  [super didReceiveMemoryWarning];
  // Dispose of any resources that can be recreated.
}

#pragma mark - WebView Delegate
- (void)webViewDidFinishLoad:(UIWebView *)theWebView {
    [ super webViewDidFinishLoad:theWebView ];
}

- (void)webViewDidStartLoad:(UIWebView *)theWebView {
    [ super webViewDidStartLoad:theWebView ];
}

- (void)webView:(UIWebView *)theWebView didFailLoadWithError:(NSError *)error {
    [super webView:theWebView didFailLoadWithError:error];
}

- (BOOL)webView:(UIWebView *)theWebView
     shouldStartLoadWithRequest:(NSURLRequest *)request
                 navigationType:(UIWebViewNavigationType)navigationType {
    return [super webView:theWebView
     shouldStartLoadWithRequest:request
                 navigationType:navigationType];
}

@end

我还添加了我第一次启动屏幕时得到的日志

> 2014-07-31 12:09:20.164 sample[16948:60b] Multi-tasking -> Device: YES,
> App: YES 2014-07-31 12:09:20.167 sample[16948:60b] Unlimited access to
> network resources 2014-07-31 12:09:20.168 sample[16948:6e0f] [DEBUG]
> [WL_INIT] -[WLImpl initWL] in WLImpl.m:117 :: START 2014-07-31
> 12:09:20.244 sample[16948:60b] [CDVTimer][wlapp] 0.119984ms 2014-07-31
> 12:09:20.245 sample[16948:60b] [CDVTimer][push] 0.069976ms 2014-07-31
> 12:09:20.245 sample[16948:60b] [CDVTimer][TotalPluginStartup]
> 0.966966ms 2014-07-31 12:09:20.263 sample[16948:60b] [DEBUG] [WL_INIT] -[WLImpl _wlInitDidCompleteWithResult:] in WLImpl.m:97 :: END 2014-07-31 12:09:20.269 sample[16948:60b]
> worklight:///Users/rahul.singh1/Library/Application Support/iPhone
> Simulator/7.1/Applications/50D15A9F-732F-4EAE-9463-6F3F0366002B/sample.app/www/default/index.html
> 2014-07-31 12:09:20.271 sample[16948:60b] Resetting plugins due to page
> load. 2014-07-31 12:09:20.914 sample[16948:60b] GET_BAG_ITEMS
> 2014-07-31 12:09:20.915 sample[16948:2d07] Multi-tasking -> Device:
> YES, App: YES 2014-07-31 12:09:20.917 sample[16948:2d07] Unlimited
> access to network resources 2014-07-31 12:09:20.930 sample[16948:60b]
> log1 2014-07-31 12:09:20.944 sample[16948:60b] Failed to load webpage
> with error: The operation couldn’t be completed. (NSURLErrorDomain
> error -999.) 2014-07-31 12:09:20.946 sample[16948:2d07] [WARN] [NONE]
> Initialization option 'connectOnStartup' is deprecated. Use
> WL.Client.connect() to connect to the Worklight Server. 2014-07-31
> 12:09:20.970 sample[16948:5613] [DEBUG] [NONE] ondeviceready event
> dispatched 2014-07-31 12:09:20.972 sample[16948:6d0b] [WARN] [NONE]
> Initialization options 'enableLogger' and 'logger' are deprecated. Use
> WL.Logger.config to set logger behavior. 2014-07-31 12:09:20.972
> sample[16948:8103] [DEBUG] [NONE] wlclient init started 2014-07-31
> 12:09:20.974 sample[16948:8203] [DEBUG] [NONE] Read cookies: null
> 2014-07-31 12:09:20.975 sample[16948:1303] [WARN] [NONE] Initialization
> option 'analytics' is deprecated. Use WL.Analytics.enable/disable to
> set analytics data capture. 2014-07-31 12:09:20.975 sample[16948:8303]
> [DEBUG] [NONE] CookieMgr read cookies: {} 2014-07-31 12:09:20.976
> sample[16948:8703] [DEBUG] [NONE] before: initOptions.onSuccess
> 2014-07-31 12:09:20.977 sample[16948:8803] [DEBUG] [NONE] after:
> initOptions.onSuccess 2014-07-31 12:09:20.977 sample[16948:8a03]
> [DEBUG] [NONE] wlclient init success 2014-07-31 12:09:20.977
> sample[16948:8903] [DEBUG] [NONE] added onPause event handler 
> 2014-07-31 12:09:21.089 sample[16948:60b] *** -[NSKeyedUnarchiver
> initForReadingWithData:]: data is NULL

【问题讨论】:

  • 我已经用代码更新了问题。请务必让我知道我在哪里做错了或需要解决什么问题。
  • 最近修复了您使用的确切版本?
  • 我正在使用 IBM Worklight Studio V6.2.0.0。有没有更新的版本或者这是最新的?为什么会发生它第一次没有加载,然后再正常工作。是否与在 webview 上加载 html 和 javascript 有关?
  • @RahulSingh,你能以我们可以运行的 Xcode 项目的形式提供这个吗?删除我们不应该看到的内容,或者创建一个仅显示问题的演示项目...
  • 这可能是因为您在框架成功初始化之前尝试加载资源;将要加载的资源(起始页)的准备工作移至其他视图控制器。

标签: iphone ios7 uiwebview ibm-mobilefirst


【解决方案1】:

我并不完全清楚你的情况。
您是否希望此视图控制器在 Worklight 之前呈现,或者之后通过点击按钮或类似方式呈现。

您可能希望查看以下博客文章中提供的示例项目: Integrating a Worklight-based iOS app with Xcode Storyboard

虽然博客文章讨论了如何在 Xcode Storyboard 的上下文中执行此操作,但这不是必需的。它也可以是 XIB...

该博客展示了如何“重新排序”启动序列,使其与 Storyboard 合二为一,并能够从 Cordova 视图控制器(包含 Web 视图)遍历到其他视图控制器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-12
    • 2014-07-09
    • 1970-01-01
    • 2014-09-08
    • 1970-01-01
    • 2020-02-28
    相关资源
    最近更新 更多