简体   繁体   English

OSX WebView中的EXC_BAD_ACCESS

[英]EXC_BAD_ACCESS in OSX WebView

I'm building a simple application with a web view to wrap an HTML5 app for OSX. 我正在构建一个带有Web视图的简单应用程序,以包装用于OSX的HTML5应用程序。 The web view listens for messages from the app, then calls some javascript functions to send some data back. 网络视图会监听来自应用程序的消息,然后调用一些javascript函数将一些数据发送回去。 This works perfectly until I try to load another page onto the web view. 直到我尝试将另一个页面加载到Web视图上之前,此方法都可以正常工作。 It looks like in the background the web view releases the ResourceLoadDelegate then tries to call it again, resulting in my error message. 似乎在后台,Web视图释放了ResourceLoadDelegate,然后尝试再次调用它,导致出现错误消息。

My project uses one class as a giant app delegate, and I've the UIDelegate, ResourceLoadDelegate, and FrameLoadDelegate all set to "self". 我的项目使用一个类作为巨型应用程序委托,并且我将UIDelegate,ResourceLoadDelegate和FrameLoadDelegate都设置为“ self”。 I don't get the error if I don't have the ResourceLoadDelegate set, but then I can't receive messages. 如果没有设置ResourceLoadDelegate,我不会收到错误消息,但是我无法接收消息。

Does anyone know what my problem could be? 有人知道我的问题是什么吗? Here is my code: 这是我的代码:

My header: 我的标题:

@interface BFAppDelegate : NSObject <NSApplicationDelegate> {
    WebView *webView;
} 

@property (nonatomic, strong) IBOutlet WebView *webView;

@end

My class: 我的课:

@implementation BFAppDelegate
@synthesize webView;

- (void)applicationDidFinishLaunching:(NSNotification *)notification {
    [self.webView setUIDelegate:self];
    [self.webView setResourceLoadDelegate:self];
    [self.webView setFrameLoadDelegate:self];
}

-(void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:message]];
    [self.webView loadRequest:request];
}

@end

Check that you have linked WebKit.framework in the General Settings of your Target. 检查您是否已在“目标”的“常规设置”中链接了WebKit.framework

  1. In the Project Browser click on the Project (first item) 在项目浏览器中,单击项目(第一项)
  2. Go to the "General"-Tab 转到“将军”标签
  3. Under "Linked Frameworks and Libraries" click the plus icon. “链接的框架和库”下,单击加号图标。
  4. Search for WebKit.framework 搜索WebKit.framework
  5. Select it and hit "Add". 选择它并点击“添加”。
  6. Boom! 繁荣! We're done! 大功告成!

Also don't forget to import WebKit/WebKit.h in your header file(s). 同样不要忘记在您的头文件中导入 WebKit / WebKit.h

链接的框架和库

I hope I can help you with that. 希望能为您提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM