我有一个WKWebView置于模态中的问题:
我打开并模态并在里面放置一个WKWebView。我加载一个网址,一切正常,直到我尝试单击(焦点)输入字段,然后它只是崩溃并关闭模式。有趣的是它可以在我的MAC上工作,但在另一个上却没有。两者都在使用MacOS Sierra 10.12.6
我还尝试了一个空白的html页面,其中只放置了一个输入并再次崩溃。
这是我的代码:
#import <Foundation/Foundation.h>
#import <Webkit/WebKit.h>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#define MSGSZ 128
using namespace std;
typedef struct msgbuf {
long mtype;
char mtext[MSGSZ];
} message_buf;
@interface Window_delegate : NSObject <NSWindowDelegate>
@end
@interface App_delegate : NSObject <NSApplicationDelegate>
@property (weak, nonatomic) NSWindow *_window;
@end
@implementation App_delegate
-(instancetype)init:(NSWindow*)parent_window
{
if (self = [super init]) {
self._window = parent_window;
return self;
}
return nil;
}
-(void)applicationDidFinishLaunching:(NSNotification *)a_notification
{
WKWebViewConfiguration *theConfiguration =
[[WKWebViewConfiguration alloc] init];
// theConfiguration.suppressesIncrementalRendering=YES;
WKWebView *wb = [[WKWebView alloc] initWithFrame:self._window.contentView.frame configuration:theConfiguration];
wb.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
NSURL *url = [NSURL URLWithString: @"http://p416884.mittwaldserver.info/site/public"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[wb loadRequest:request];
wb.frame = CGRectMake(self._window.contentView.frame.origin.x,self._window.contentView.frame.origin.y, self._window.contentView.frame.size.width, self._window.contentView.frame.size.height);
[self._window.contentView addSubview:wb];
}
@end
void start_program(void)
{
NSApplication *app = [NSApplication sharedApplication];
// Critical to have this so that you can add menus
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
NSWindow *window =
[[NSWindow alloc]
initWithContentRect:NSMakeRect(0, 0, 1200, 900) styleMask: NSWindowStyleMaskClosable backing: NSBackingStoreBuffered defer: YES];
[window center];
[window makeKeyAndOrderFront:window];
[window setStyleMask:[window styleMask] | NSWindowStyleMaskTitled | NSWindowStyleMaskResizable];
[window setTitle:@"Saint-Gobain Baustoffwelt"];
App_delegate *application_delegate = [[App_delegate alloc] init:window];
app.delegate = application_delegate;
[app activateIgnoringOtherApps:YES];
[app run];
}
int main(int argc, char **argv)
{
// std::cout << "Starting Application\n";
@autoreleasepool {
start_program();
}
return 0;
}
这是我在Console.app崩溃时得到的:link to screenshot
如果你能以某种方式帮助我,我将非常感激..