WebKitErrorFrameLoadInterruptedByPolicyChange what is that? - iphone

I get WebKitErrorFrameLoadInterruptedByPolicyChange in
(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
using FBDialog when trying to share an URL for the first time in
all next try are OK.
Do you have an idea why?
Thanks

Are you sure that you receive WebKitErrorFrameLoadInterruptedByPolicyChange?
There is a problem with SSO in Facebook connect. When an application become active after giving authorization in Safari or Facebook App, web view fails to load your initial share request.
I receive Error Domain=NSURLErrorDomain Code=-999. You can change if statement in (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error as follow to fix it:
if (!(([error.domain isEqualToString:#"NSURLErrorDomain"] && error.code == -999) ||
!([error.domain isEqualToString:#"WebKitErrorDomain"] && error.code == 102))) {
[self dismissWithError:error animated:YES];
}
https://github.com/ShareKit/ShareKit/issues/56

Related

facebook Security Warning while user has enabled secure login - iPhone

I am working on an application which uses FB login. For login from faceBook I am using FBGraph and it works fine if users have disabled secure login in their account, but if user enables the secure login then it gives following message..
Here is my code i used for login
self.fbGraph = [[FbGraph alloc] initWithFbClientID:client_id];
[fbGraph authenticateUserWithCallbackObject:self andSelector:#selector(fbGraphCallback:)
andExtendedPermissions:#"user_photos,user_videos,publish_stream,offline_access,user_checkins,friends_checkins"];
EDIT:
From suggestions from current answers, I have added following code in my FBGraph.m But with this code i am getting token nil.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
NSLog(#"\n\n\nrequest.URL.relativeString = %#\n\n\n",request.URL.relativeString);
if([request.URL.relativeString hasPrefix:#"https://www.facebook.com/connect/login_success.html" ]||[request.URL.relativeString hasPrefix:#"http://www.facebook.com/connect/login_success.html" ]||[request.URL.relativeString hasPrefix:#"http://m.facebook.com/connect/login_success.html" ])
{
[self.webView stopLoading];
[[self.webView superview] removeFromSuperview];
//tell our callback function that we're done logging in :)
if ( (callbackObject != nil) && (callbackSelector != nil) ) {
[callbackObject performSelector:callbackSelector];
}
return NO;
}
return YES;
}
I have also changed
self.redirectUri = #"http://www.facebook.com/connect/login_success.html";
To
self.redirectUri = #"http://m.facebook.com/connect/login_success.html";
But still no success....
Please tell me the solution for FB Login.....
Thanks...........
You should use Facebook's official SDK.
Download it from here - Facebook SDK
Facebook says
The Facebook SDK 3.8 for iOS is a minor update that adds XCode 5 and
iOS 7 support, stability fixes, automatic permissions refresh and the
ability to specify batch request parameters to (FBRequestConnection).
Change url :
self.redirectUri = #"http://www.facebook.com/connect/login_success.html";
FBGraph.m to
self.redirectUri = #"https://m.facebook.com/connect/login_success.html";
and check.
This is not an error , but just a security warning from Facebook. And I have resolved it in my application to escape from this.
Check the below method in FbGraph.m file
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
if([request.URL.relativeString hasPrefix:#"https://www.facebook.com/connect/login_success.html" ])
self.webView.hidden=TRUE;
return YES;
}
check if it's currently present in file. If not then go with it.

iOS FaceBook ingegration, Feeds dialog shows blank the first time

Im using the latest FaceBook SDK for iOS, everything works fine except the first time I'm using the
[facebook dialog:#"feed" andParams:params andDelegate:self];
the dialog shows a empty canvas, and dismisses itself, the next time i try the same call the dialog is just fine.
So to reproduce this error, I'm deleting the app from Facebook to initiate the authorization, session, login etc.
Anyone else with the same problem?
I also face same issue like this. I have fix it by changing in FBDialog.m file
change
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
// 102 == WebKitErrorFrameLoadInterruptedByPolicyChange
if (!([error.domain isEqualToString:#"WebKitErrorDomain"] && error.code == 102)) {
[self dismissWithError:error animated:YES];
}
}
to
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
// 102 == WebKitErrorFrameLoadInterruptedByPolicyChange
if (!([error.domain isEqualToString:#"WebKitErrorDomain"] && error.code == 102)) {
// -999 == "Operation could not be completed"
if (!(([error.domain isEqualToString:#"NSURLErrorDomain"] && error.code == -999) ||
([error.domain isEqualToString:#"WebKitErrorDomain"] && error.code == 102))) {
[self dismissWithError:error animated:YES];
}
}
}
I hope this will solve your problem......

How to handle app URLs in a UIWebView?

I recently found that my UIWebView was choking on ITMS links. Specifically, from the UIWebView in my app, if I navigate to a site such as this one and click the "Available on the App Store" link, UIWebView would error out with "Error Domain=WebKitErrorDomain Code=101 The URL can't be shown."
After a bit of Googling, I realized that I needed to catch requests for app links and have iOS handle them. I started out by looking to see if the scheme starts with "itms" in -webView:shouldStartLoadWithRequest:navigationType:, but realized that there might be other kinds of app links that the system can handle. So I came up with this, instead:
- (void)webView:(UIWebView *)wv didFailLoadWithError:(NSError *)error {
// Give iOS a chance to open it.
NSURL *url = [NSURL URLWithString:[error.userInfo objectForKey:#"NSErrorFailingURLStringKey"]];
if ([error.domain isEqual:#"WebKitErrorDomain"]
&& error.code == 101
&& [[UIApplication sharedApplication]canOpenURL:url])
{
[[UIApplication sharedApplication]openURL:url];
return;
}
// Normal error handling…
}
I have two questions about this:
Is this sane? I'm specifically checking for the error domain and error code and fetching the URL string from the userInfo. Is that stuff likely to remain?
This does work for the above-linked app store link, but when I switch back to my app, there appears to have been a subsequent failed request that failed with "Frame load interrupted". how can I get rid of that? It doesn't happen when I have the OS handle the request from -webView:shouldStartLoadWithRequest:navigationType:, so it's a bit annoying.
How do you handle such requests?
Here's what I came up with. In webView:shouldStartLoadWithRequest:navigationType:, I ask the OS to handle any non-http and non-https requests that it can, like so:
- (BOOL)webView:(UIWebView *)wv shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
// Determine if we want the system to handle it.
NSURL *url = request.URL;
if (![url.scheme isEqual:#"http"] && ![url.scheme isEqual:#"https"]) {
if ([[UIApplication sharedApplication]canOpenURL:url]) {
[[UIApplication sharedApplication]openURL:url];
return NO;
}
}
return YES;
}
This works very well except for the bloody "Frame Load Interrupted" error. I had thought that by returning false from webView:shouldStartLoadWithRequest:navigationType: that the web view would not load the request and therefore there would be no errors to handle. But even though I return NO above, I still "Frame Load Interrupted" error. Why is that?
Anyway, I'm assuming it can be ignored in -webView:didFailLoadWithError::
- (void)webView:(UIWebView *)wv didFailLoadWithError:(NSError *)error {
// Ignore NSURLErrorDomain error -999.
if (error.code == NSURLErrorCancelled) return;
// Ignore "Fame Load Interrupted" errors. Seen after app store links.
if (error.code == 102 && [error.domain isEqual:#"WebKitErrorDomain"]) return;
// Normal error handling…
}
And now iTunes URLs work properly, as do mailto:s and app links.
Starting with Theory's code, examine the URL for "itms" scheme(s) (this method can be called multiple times due to redirects). Once you see an "itms" scheme, stop the webView from loading and open the URL with Safari. My WebView happens to be in a NavigationController, so I pop out of that after opening Safari (less flashing).
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request
navigationType:(UIWebViewNavigationType)navigationType
{
if ([[[request URL] scheme] isEqualToString:#"itms-apps"]) {
[webView stopLoading];
[[UIApplication sharedApplication] openURL:[request URL]];
[self.navigationController popViewControllerAnimated:YES];
return NO;
} else {
return YES;
}
}
Does it help if you register your app for handling itms: links?
e.g.
http://inchoo.net/iphone-development/launching-application-via-url-scheme/
You may start with scheme http but then get an itms redirect, which could fail if your app is not registered as handling that scheme.

Sending loadRequest messages to UIWebView before current view is finished loading causes error

I have a webview as the detail view of a tableView navigation based app. There are "UP" and "DOWN" arrows on the navigationBar that the user can use to page through the different detail views.
Everything works fine as long as the user only clicks the "UP" or "Down" arrows once. But if the arrows are clicked multiple times and the loadRequest message is sent twice to the UIWebView, I get the error message "NSURLErrorDomain error -999" from my didFailLoadWithError method.
It seems like if a loadRequest is sent while the page is currently loading a view the error is sent. As long as the page is finished loading everything works fine.
I've tried a variety of solutions, all with the same result.
Thanks for the help!
I had the same problem today - try also this approach:
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
NSLog(#"didFail: %# stillLoading:%# error code:%i", [[webView request]URL], (webView.loading?#"NO":#"YES"), [error code]);
if ([error code] != -999) {
// Handle your other errors here
}
}
Reference
I solved the problem by calling:
[self.myWebView stopLoading];
myWebView.delegate = nil;
before reloading the new URL.
Before I send the new loadRequest I call:
myWebView.delegate = self;

Facebook iPhone SDK: show a progress bar while uploading an image

I want to show a progress bar while my iPhone app is uploading an image to Facebook. Is it possible?
Can I do it with every FBRequest that I make? I also use FBRequest to check extended permission and sometimes takes a lot of time.
Thank you.
For the progress bar there is a little hack you can do. In the FBRequest.h file add this line in the FBRequestDelegate protocol:
- (void)request:(FBRequest *)request didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite;
After that in the FBRequest.m file add this function:
- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite {
if ([_delegate respondsToSelector:#selector(request:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:)]) {
[_delegate request:self didSendBodyData:bytesWritten totalBytesWritten:totalBytesWritten totalBytesExpectedToWrite:totalBytesExpectedToWrite];
}
}
Now your delegate will receive a message every time more data it's posted to the server. So basically if you implement this into your delegate you should see some activity in your log:
- (void)request:(FBRequest *)request didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
{
NSLog(#"%d bytes out of %d sent.", totalBytesWritten, totalBytesExpectedToWrite);
}
Let me know if you have any problems hacking this into the current Facebook SDK.
You can't know when it gonna log you in but you can put an UIActivityIndicatorView.
You start it when you click on publish button and you end it when you enter the 'didConnect' method