Load an URL into a webview from outside the application does not work
I'm trying to load an URL into a webview from outside the application. I've set my info.plist 开发者_如何学Pythonproperly 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 ?
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?
精彩评论