facebook login on iphone leaves blank page - facebook

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;
}

Related

Pago payment gateway Integration [duplicate]

This question already has answers here:
Accept payment on ios apps?
(4 answers)
Closed 9 years ago.
I would like to add a payment module on my Iphone Application that I am going to build,
I want the users to pay using Pago. When webpage loads a button is displayed, on clicking the button a new page opens in a new window.
On that page user enters the payment details and payment is processed. As we have no control over this window, So we are not able to call our custom url to return to our app on payment success.
So how can I return to App on payment success?
There is no easy way to do it.
Try opening the page in web view and add when the url of the success page match to the url in web view display the success message.
I want the users to pay using Pago. When webpage loads a button is displayed, on clicking ? the button a new page opens in a new window.
Does the new page opens inside a webview in your app?
If so, you just have to get the URL you get on payment success (if you can) and use the following web view delegate method to catch the URL:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSString *urlString = [NSString stringWithFormat:#"%#", request.URL];
// If not found, load url
if ([urlString rangeOfString:#"http://you-url"].location == NSNotFound)
{
return YES;
}
// If found, intercept
else
{
// Do what you want here
return NO;
}
}

Facebook login fails in UIWebView

In my app I have to load a web page in UIWebView where user can login with Facebook. The problem is that when user clicks login, blank page appears.
Is it possible to get back to first page and be logged in?
Web page works perfectly in Safari and opens new window and after login it closes it and gets back to where it left.
EDIT: wrong URL was provided to UIWebView
I think the sample of facebook SDK for iOS does the log in way you want.
Please refer to the link:
facebook-iOS-SDK-sample: https://github.com/facebook/facebook-ios-sdk/tree/master/sample/Hackbook
Especially this part in https://github.com/facebook/facebook-ios-sdk/blob/master/sample/Hackbook/Hackbook/RootViewController.m
/**
* Show the authorization dialog.
*/
- (void)login {
HackbookAppDelegate *delegate = (HackbookAppDelegate *)[[UIApplication sharedApplication] delegate];
if (![[delegate facebook] isSessionValid]) {
[[delegate facebook] authorize:permissions];
} else {
[self showLoggedIn];
}
}
When you click on log in button, it will open a login dialog, and ask for permission. This is what it looks like: https://developers.facebook.com/docs/mobile/screenshots/ios/#iphone-native
I think the best way to implement the "facebook-related" app is to start with the Hacbook. It is really a nice and detailed sample.
If you want to reload a specific url after the facebook login popup is closed to prevent being stuck on a blank page you can use this code.
First include the UIWebViewDelegate and set your delegate somewhere in your code.
[yourwebView setDelegate:self];
Then use the shouldStartLoadWithRequest method to check request url for close_popup.php which is used by Facebook to close their popup.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSString *urlString = [NSString stringWithFormat:#"%#", request];
if ([urlString rangeOfString:#"close_popup.php"].location == NSNotFound) {
//The close_pop.php is not found. (Do nothing)
} else {
//Facebook closed the popup so we should load the page we now want the user to see.
NSURL*url=[NSURL URLWithString:#"http://www.example.ca/thepageyouwanttoreload.html"];
NSURLRequest*request=[NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
return YES;
}
SSL issue? As per Joanne use the facebook SDK and you get loads of extra functionality for free, including logging in via the facebook native app if its installed.

iPhone: After UIWebView opens external browser, then returning to app opens it a second time

I have a UIWebView which loads an HTML page which has some links to the App Store (<a herf="http://itunes/bla/bla/bla"> type of links).
Clicking a link, opens external Safari, then opens external App Store app and successfully goes to correct page.
If you then click Home button and return to springboard and click on app again, it will briefly open to the the UIWebView that was displayed and then jump to external Safari and external App Store app again.
If you go back to app one more time it stays in the app.
So what is happening is that returning to app after opening external browser link from UIWebView HTML page, will then jump back to the same link a second time.
Anybody have any ideas what might be causing this?
Am using Xcode 4.2.1 and it happens in simulator as well as on an actual device (iPad 1 with iOS 4.3).
EDIT - SOLUTION:
Ok, here is what I had to do to solve the problem (Thanks to Ben's response below who got me looking at the right areas):
This was my original method:
- (BOOL)webView:(UIWebView *)_webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if (didLoad) { //Do not jump to URL when view first loads
return YES;
}
[[UIApplication sharedApplication] openURL:[request URL]];
return YES;
}
And this is my fixed method that does not keep jumping to URL:
- (BOOL)webView:(UIWebView *)_webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if (didShowURL) { //Do not jump to URL when returning to app
didShowURL = 0;
return NO;
}
if (didLoad) { //Do not jump to URL when view first loads
return YES;
}
didShowURL = 1;
[[UIApplication sharedApplication] openURL:[request URL]];
return YES;
}
I would suggest using the itms-apps:// protocol for your link. This will send the user directly to the application in the App Store without the need for a redirect.
NSURL *appStoreLink = [NSURL URLWithString:#"itms-apps://itunes.apple.com/us/app/instagram/id389801252?mt=8"];
[[UIApplication sharedApplication] openURL:appStoreLink];
Your webview is being reloaded to its last page (the app store page) and is automatically redirecting the user away again. You just need to make sure that when the app is reloaded it is not trying to load the app store link again.
Depending on your app setup you could use
viewWillAppear
And reload the original HTML page with the links every time the view is brought to the front.

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

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.

Call 'action' on HTML web form in a UIWebView

I'm trying to skip the login page of a website, so I can give the user a more aesthetically appealing login page, and save their login credentials for automatic login in the future. So far I have two UITextFields, and a UIButton. The user enters their username and password, and upon pressing the UIButton their details are entered into the actual webform on the sites login page, and the subsequent 'logged-in' page is shown in a UIWebView. The webView will be hidden while the app logs the user in, and then presented when the 'logged-in' page has loaded.
I've managed to populate the webform, but simply can't actually submit it! I'm sure there's a very simple solution!
This is the code I have so far, and if there's a better way I should be doing this let me know!
-(IBAction)login:(id)sender
{
// Create js strings
NSString *loadUsernameJS = [NSString stringWithFormat:#"var username = document.getElementsByName('username')[0]; username.value='%#';", username.text];
NSString *loadPasswordJS = [NSString stringWithFormat:#"var password = document.getElementsByName('password')[0]; password.value='%#';", password.text];
// Autofill the form - this works, and I can see the values being put into the webform
[self.webView stringByEvaluatingJavaScriptFromString: loadUsernameJS];
[self.webView stringByEvaluatingJavaScriptFromString: loadPasswordJS];
// This is the method I have tried to submit the form, but nothing happens (ct100 is the ID of the form).
[self.webView stringByEvaluatingJavaScriptFromString:#"document.ct100.submit();"];
}
Below Approach might be helpful to you
Put this code inside the didFinishLoading Method Of UIWebView Protocol
Fill The USerId
[webView stringByEvaluatingJavaScriptFromString:#"document.getElementById('username').value = 'userId'"];
Fill The Password
[webView stringByEvaluatingJavaScriptFromString:#"document.getElementById('password').value = 'password'"];
Call Submit Button as below
[webView
stringByEvaluatingJavaScriptFromString:#"document.forms['login_form'].submit();"];
Herelogin_form is the Name of You Form
Note: You have to manage one thing once you have filled the Credential clicked the Submit button. you need to make some BOOL or something else for avoiding the loading repetition of UIWebView.
Try:
[webView stringByEvaluatingJavaScriptFromString:#"document.getElementById(\"ct100\").submit()"];
Your view controller needs to implement the UIWebViewDelegate protocol and set itself as the UIWebView's delegate. Returning YES from webView:shouldStartLoadWithRequest (see code below) will allow the web view to navigate to any url the your form is submitting to.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(#"Allow navigation to request = %#", request);
return YES;
}