Appying our own action to Facebook Login button & closing all Facebook screens. - iphone

I am using fbconnect api in my project. When the login dialog gets opened where we entered our credentials, when we click on login button then it is redirected to the publish page how can we close the login page or post to wall page or view.
My problem is I don't want to open any page belongs to face book API, instead i want to open my own page. Any one can help or suggest.

In FBConnect there is a class FBDialog which is using UIWebView for Facebook login authentication. The FBDialog class implements the UIWebView delegate protocol. So if you want to perform your action on login button press then you can handle it in FBDialog.m in UIWebView delegate -
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
which will call when you press on login button.

You can open your own view depending upon your requirement. After successful Login following delegate method is called
- (void)session:(FBSession*)session didLogin:(FBUID)uid
{
self.usession=session;
[self postToWall];
}
Here i am calling my own custom method postToWall. Where i create publish dialog as below:
-(void)postToWall
{
FBStreamDialog *dialog=[[[FBStreamDialog alloc]init]autorelease];
dialog.userMessagePrompt=#"Enter Message to Post";
[dialog show];
}
You can create your own view in postToWall in place of FBStreamDialog OR if you want to load request of another page then load that URL in Web View of FBStreamDialog.m class.

Related

facebook login on iphone leaves blank page

I created a simple test html page that contains a facebook like box. For testing purpose I uploaed the test page to my server.
On the desktop (being log out of facebook) there is the following situation:
Click on like
A popup appears with a form for login
After login the popup is closed and the like count is raised
However, using it on my iphone in chrome browser and being logged out of facebook the following happens:
Click on the like button
Redirect to the facebook login page
After login I'm redirected to a blank page.
The screenshot below shows the problem:
Is there a possibility to avoid this?
EDIT: The same happens when I try this in an iOS app using a UIWebView.
Okay, I found a solution for doing this in my iOS app for an integrated UIWebView.
When someone is not logged in to facebook a popup opens and requests a login. After logging in the user is redirected back to the page from where he hit the like button. However in the UIWebView this redirect URL leaves the user with a blank page. The solution to the problem is to intercept the redirect URL and reload the page with the like button.
So, with UIWebView one can intercept the requests before the actual webpage is loaded and react on certain URLs. The code for this look like this:
- (void)viewDidLoad
{
[super viewDidLoad];
self.webview.delegate = self;
[self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.example.com/facebook_like_box.html"]]];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if( [[request.URL description] rangeOfString:#"lugins/close_popup.php"].location != NSNotFound) {
// We intercepted the redirect URL of facebook after logging in. Instead of loading a blank page recall the URL of the like box
// manually on the uiwebview.
[self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.example.com/facebook_like_box.html"]]];
//returning NO indicates the the page is not further loaded.
return NO;
}
//Any other page should be loaded
return YES;
}

how to perform an action in iphone application on click in webview

I need to implement a functionality such that I have there is a login screen which sends an http request packet, gets a json response(a boolean and a routing link) and opens a webview. I have done this successfully. But further what I need to do is that when I click sign out in the webview, I should get back to the native login screen.How can I achieve that?
Check this call back method
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
}
You get this call back when you click link in webview.

Facebook API not calling delegate(request) methods if device having Facebook App

In my app am using Facebook api and in my device am having Facebook app(FBApp) also.
In my app i provided a button to login when we click on button it is opening FBApp login screen and after that it is coming to my app.
Here the following methods are not firing
-(void)request:(FBRequest *)request didReceiveResponse:(NSURLResponse *)response
-(void)request:(FBRequest *)request didLoad:(id)result
This is the button action
- (IBAction)LoginOrLogout
{
// If the user is not connected (logged in) then connect. Otherwise logout.
if (!isConnected)
{
[messageTextField setHidden:NO];
[facebook authorize:permissions];
// Change the lblUser label's message.
**[lblUser setText:#"Please wait..."];** //struck here only not firing delegate response methods above
}
else
{
[facebook logout:self];
[messageTextField setHidden:YES];
[lblUser setText:#"Tap on the Login to connect to Facebook"];
}
isConnected = !isConnected;
[self setLoginButtonImage];
}
Without FBApp it is calling delegate methods successfully.How can we solve this.
Any one can help or suggest.
Actually when you tap on authorize then it will open safari or if there is facebook app on device then it will open facebook app otherwise it will open facebook in safari. If you don't want to open the safari and facebook app then in facebook.m change this statement everywhere where it is calling to NO.
[self authorizeWithFBAppAuth:NO safariAuth:NO];
I was only able to receive those notifications on the AppDelegate class. I tried to create an util class that could be plugged in every project so it could help people using the Facebook API. The problem is that even tho I set the delegate to my util class, the delegate's methods were never called. Try to put then on the AppDelegate..

Alertview in webapp - This link opens in a new window http://wwww

I am currently developing a little webapp with iWebKit I joined a UIWebView.
And I have a little problem, I would like the external links before opening in Safari displays a alertview "This link opens in a new window".
AlertView With:
Title: External Links (No URL)
Message: Would you open this link external mobile safari ?
Button: OK Cancel
How to do that just please?
Thank you very much for your help;)
In the object that is designated as the UIWebViewDelegate add the following:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
return [self verifyUserWantsToNavigateAwayFromApp];
}
The method that you'll have to write verifyUserWantsToNavigateAwayFromApp. Is where you should pop up the alerts and wait for the UIAlertViewDelegate to get the user's answer. Return YES to navigate, NO to cancel.

Have iPhone webpage URL open in specific view in application

I have an application that acts like an internet browser for one webpage. If the webpage is in one view, can I have it act so when a specific URL is selected that it will open the URL in a different view?
Yes. In your webViewController, implement this
(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
Check to see if it's the url you're interested in, then create and push a view that displays the web page.
Oh, and return NO to prevent the load from occurring in this view.