简体   繁体   中英

Can I open an URL(a Facebook page) in a FBDialog or something in FBConnect?

I am struggling to find this. Can I open a URL in a FBDialog or using something in FBConnect. I tried to do it like the following. But it doesn't seem to be working.

FBDialog *dlg = [FBDialog new];
[dlg loadURL:@"http://www.facebook.com/pages/Apple-Inc/137947732957611" get:nil];

I don't even know whether this is possible or not. Can you guys please help me?

There are 2 problem to prevent you from your code. First, when you pass a url to -loadURL:get: method, Facebook iOS SDK rebuild the real url base on yours. So, the url you passed will not get into the webview finally. What you need to do is implementing a method in FBDialog.m like this:

-(void)hackLoadURL:(NSString*)url withDelegate:(id)delegate {
    _webView.delegate = delegate;
    [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
}

The second problem is that you need to hack the

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;

delegate method and replaced with the one you make implementation. But in order to keep the original Facebook SDK works, you need to add below code to FBDialog.m

_webView.delegate = self;

within -loadURL:get: method, and before this line

[_webView loadRequest:request];

finally, you need to implement

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;

yourselves in your class, and use

FBDialog *dlg = [FBDialog new];
[dlg hackLoadURL: yourExpectUrl withDelegate: self];

to do what you wanted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM