【发布时间】:2011-04-25 17:09:27
【问题描述】:
我正在尝试从应用程序外部将 URL 加载到 webview 中。我已经正确设置了我的 info.plist 以支持 http、https。我的应用程序出现在处理程序列表(safari 首选项盘)中。 这是我的代码
我的 awakefromnib 里有这个
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]]];
}
如果我 nslog 显示它的 url(所以它正确地得到它)。我的下一个方法也被调用。这种方法在我的应用程序内部工作正常。
问题在于,当我单击应用程序外部的链接时(一旦应用程序被选为默认浏览器)。我弹出窗口,但它没有加载 URL。它什么也不做。 任何想法 ?
【问题讨论】:
-
还有什么问题?有任何错误、发生了什么行为以及您的预期是什么?
-
哇,抱歉,是的,我忘记了这个问题。因此,点击浏览器外部的 URL 会打开它,但 webiew 只是不加载 URL。
标签: objective-c cocoa http webview httphandler