从应用程序外部将 URL 加载到 Web 视图中不起作用
我正在尝试从应用程序外部将 URL 加载到 Web 视图中。我已正确设置 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。它只是什么都不做。 有什么想法吗?
I'm trying to load an URL into a webview from outside the application. I've set my info.plist properly to support http, https. My app appear in the handler list (safari preference pan).
Here is my code
I have this in my awakefromnib
NSAppleEventManager *em = [NSAppleEventManager sharedAppleEventManager];
[em
setEventHandler:self
andSelector:@selector(getUrl:withReplyEvent:)
forEventClass:kInternetEventClass
andEventID:kAEGetURL];
And then
//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]]];
}
If i nslog the url it show it (so it properly get it). My next method is also called. This method work fine from inside my app.
The problem is that when I click in a link outside of my app (once the app is selected as default browser). I popup the window but it not load the URL. It just does nothing.
Any idea ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
webview的“mainFrame”方法是什么?这是自定义类吗?您是否将网络视图的框架添加到窗口的框架中?
What is the "mainFrame" method of webview? Is that a custom class? Did you add the web view's frame to the window's frame?