Objective c 从应用程序外部将URL加载到webview不起作用
我正在尝试从应用程序外部将URL加载到webview中。我已正确设置了我的info.plist以支持http、https。我的应用程序出现在处理程序列表(safari首选项窗格)中。 这是我的密码 我从笔尖上拿着这个Objective c 从应用程序外部将URL加载到webview不起作用,objective-c,cocoa,http,webview,httphandler,Objective C,Cocoa,Http,Webview,Httphandler,我正在尝试从应用程序外部将URL加载到webview中。我已正确设置了我的info.plist以支持http、https。我的应用程序出现在处理程序列表(safari首选项窗格)中。 这是我的密码 我从笔尖上拿着这个 NSAppleEventManager *em = [NSAppleEventManager sharedAppleEventManager]; [em setEventHandler:self andSelector:@select
NSAppleEventManager *em = [NSAppleEventManager sharedAppleEventManager];
[em
setEventHandler:self
andSelector:@selector(getUrl:withReplyEvent:)
forEventClass:kInternetEventClass
andEventID:kAEGetURL];
然后
//get the URL from outside the application
- (void)getUrl:(NSAppleEventDescriptor *)event
withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
// Get the URL
NSString *urlStr = [[event paramDescriptorForKeyword:keyDirectObject]
stringValue];
[self initWithUrl:urlStr];
}
//Can be used as intializer to init the webview with a page
-(void)initWithUrl:(NSString *)url
{
//load the lading home page
[[webview mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
}
如果我把url记录下来,它就会显示出来(这样它就能正确地得到它)。我的下一个方法也叫做。这个方法在我的应用程序中运行良好
问题是,当我点击我的应用程序外的链接时(一旦该应用程序被选为默认浏览器)。我弹出窗口,但它没有加载URL。它什么也不做。
有什么想法吗 什么是webview的“大型机”方法?那是自定义类吗?是否将web视图的框架添加到窗口的框架中?问题是什么?任何错误,发生了什么行为,你期望什么?哇,对不起,是的,我忘记了问题。因此,点击浏览器外的URL打开它,但webview只是不加载URL。我只是以Apple文档中的示例为例,其中包括在webview对象的主框架中加载所需的URL:硬编码一些基本html,例如将主体背景设为红色,然后查看是否显示。然后,您将知道它是否正在加载webView而不是url,或者它是否甚至没有加载webView。