Not redirecting to Facebook comments in UIWebView after login
I suspect the problem you're having is related to this issue: Facebook authentication in a UIWebView does not redirect back to original page on my site asking for auth
Specifically, the standard Facebook web login process launches a new browser window dialog, and dispatches a message back to the opener to indicate login success for the redirect to occur.
Quoting a passage in the linked SO, "UIWebView doesn't support multiple windows so it can't postMessage back to your original page since it's no longer loaded."
Facebook Javascript login in native ios6 UIWebView (WORKS ON SAFARI)
Did it!
It kinda of a hack, but the js facebook sdk login on UiWebView at iOS 6 finally works.
How it could be done? It is a pure JS + Facebook JS SDK + UIWebView Delegate handling functions solution.
JS - First step)
a login button (to connect with facebook) calls this function example, that will trigger Face JS login/oauth dialogs:
function loginWithFacebookClick(){
FB.login(function(response){
//normal browsers callback
});
}
JS - Second step)
add a authResponseChange listener every time user loads the webpage ( after FB.init() ) to catch user's connected status:
FB.Event.subscribe('auth.authResponse.Change', function(response){
//UIWebView login 'callback' handler
var auth = response.authResponse;
if(auth.status == 'connected'){
//user is connected with facebook! just log him at your webapp
}
});
AND with app's UIWebView delegate functions you can handler facebook oauth responses
Objective C - Third step)
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSString *url = [[request URL] absoluteString];
//when user status == connected (has a access_token at facebook oauth response)
if([url hasPrefix:@"https://m.facebook.com/dialog/oauth"] && [url rangeOfString:@"access_token="].location != NSNotFound)
{
[self backToLastPage];
return NO;
}
return YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSString *url = [[webView.request URL] absoluteString];
if([url hasPrefix:@"https://m.facebook.com/dialog/oauth"])
{
NSString *bodyHTML = [webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"];
//Facebook oauth response dead end: is a blank body and a head with a script that does
//nothing. But if you got back to your last page, the handler of authResponseChange
//will catch a connected status if user did his login and auth app
if([bodyHTML isEqualToString:@""])
{
[self backToLastPage];
}
}
}
So, when 'redirect' user to the last loaded page, the second step is going to handler user action at facebook login dialogs.
If I got too fast with this answer, please ask me!
Hope it helps.
Android Webview and Facebook Login Not working
I was able to find a solution based on a previous question on stackoverflow.com
Making facebook login work with an Android Webview
Here is a link to my MainActivity : http://pastebin.com/KdzfhqDJ
Related Topics
Collectionview with the Horizontal Scroll with Mulitple Section
How to Animate an Svg Path in iOS
Share Video on Twitter with Fabric API Without Composer iOS
Using Generic In-App Purchase Items for a Dynamic Range of Digital Products
How to Draw a Non-Rectangle Uitextview
"This App Is Not Allowed to Query for Scheme Cydia" iOS9 Error
Detect Screen Unlock Events in iOS Swift
New Itunes User Interface Unable to Find "Ready to Upload Binary"
Core Data Store Included in App Bundle
How to Use iOS Speech Recognition in Offline Mode
Swift - Must Call a Designated Initializer of the Superclass Skspritenode Error
Orienting iOS Splash Image to Landscape/Portrait According to Launch Orientation
Not Receiving Any Push Notification in Iphone
How to Delete a Child from Firebase (Swift)
Uilabel: Background Dependent Color
How to Convert a Kcvpixelformattype_420Ypcbcr8Biplanarfullrange Buffer to Uiimage in iOS
In Os X 10.10 (Yosemite Beta), How to Test Using iOS 6.1 Simulator