Strange Behaviour while loading URL in Webview in IOS - ios

It looks simple, but don't know what goes wrong. I am trying to load a basic URL in WebView, as shown below
WebsiteWebView.delegate=self;
NSURL* url = [NSURL URLWithString:#"http://firstclasspizzaoc.com/"];
[WebsiteWebView loadRequest:[NSURLRequest requestWithURL:url]];
while loading i am getting below error everytime..
Error : Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed. (NSURLErrorDomain error -999.)" UserInfo=0xe036d20 {NSErrorFailingURLKey=http://firstclasspizzaoc.com/, NSErrorFailingURLStringKey=http://firstclasspizzaoc.com/}
2014-01-07 15:18:46.142 FirstClassPizza[1583:
Error : Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo=0xe0ef310 {NSErrorFailingURLStringKey=XXXXXXXX, NSErrorFailingURLKey=XXXXXXXX, NSLocalizedDescription=A server with the specified hostname could not be found., NSUnderlyingError=0xcbe9130 "A server with the specified hostname could not be found."}
At Browser it is loading perfectly..
Please suggest what went wrong in my code..
Any Valuable suggestions will be appreciated...
Thanks

It is due to Your Web URL http://firstclasspizzaoc.com/ can you use your url with
http://www.firstclasspizzaoc.com/

You can find your answer here :
How do I fix NSURLErrorDomain error -999 in iPhone 3.0 OS
This thread contained this description for this error: "This error may occur if an another request is made before the previous request of WebView is completed..."
I worked around this by ignoring this error and letting the webview continue to load.
if ([error code] != NSURLErrorCancelled) {
//show error alert, etc.
}

Related

upload and save video from api with UISaveVideoAtPathToSavedPhotosAlbum

I have a video that is displayed through the one api in my application. I want to upload and save it on my device and I am using this code:
- (IBAction)saveMovie:(id)sender {
NSString *path = #"http://development.s3.amazonaws.com/uploads/f1a97ec0-e47f-470e-96a6-de98d2235dd0/Biceps.mp4";
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(path)){
UISaveVideoAtPathToSavedPhotosAlbum(path, nil, nil, nil);
[self alert];
} else {
NSLog(#"incompatible video");
}
}
The link "path" is a own link to upload the file but also have the view link.
When I call the method that receives an answer
Video http://development.s3.amazonaws.com/uploads/f1a97ec0-e47f-470e-96a6-de98d2235dd0/Biceps.mp4 cannot be saved to the saved photos album: Error Domain=NSURLErrorDomain Code=-1100 "The requested URL was not found on this server." UserInfo=0x1660f300 {NSErrorFailingURLStringKey=file:///http:/xerofit-development.s3.amazonaws.com/uploads/f1a97ec0-e47f-470e-96a6-de98d2235dd0/Biceps.mp4, NSErrorFailingURLKey=file:///http:/xerofit-development.s3.amazonaws.com/uploads/f1a97ec0-e47f-470e-96a6-de98d2235dd0/Biceps.mp4, NSLocalizedDescription=The requested URL was not found on this server., NSUnderlyingError=0x16542030 "The operation couldn’t be completed. No such file or directory", NSURL=file:///http:/xerofit-development.s3.amazonaws.com/uploads/f1a97ec0-e47f-470e-96a6-de98d2235dd0/Biceps.mp4}
what's wrong?
I tried to do it from NSTemporaryDirectory and it worked. It seems that if one accepts this way.
In my case I put this url
http://qa-elb-765904057.us-west-2.elb.amazonaws.com/plugin/execute?pluginName=xxxx&pluginMethod=xxxx&clientId=b0007920-88b4-11e5-a62a-fxxxxx&token=xxx94d60-91xx-11e5-a62a-f362d1d2xxx0&file_key=Mbxxx5v6RxxxQOR.mp4
and the error was this
Video /plugin/execute cannot be saved to the saved photos album: Error Domain=NSURLErrorDomain Code=-1100 "The requested URL was not found on this server." UserInfo=0x176644e0 {NSErrorFailingURLStringKey=file:///plugin/execute, NSErrorFailingURLKey=file:///plugin/execute, NSLocalizedDescription=The requested URL was not found on this server., NSUnderlyingError=0x17661850 "The operation couldn’t be completed. No such file or directory", NSURL=file:///plugin/execute}
It seems that the entire url that was sending only detected this
/plugin/execute

initWithContentsOfURL returns nil only in iOS 5.x [duplicate]

I have been stuck with this for a while and don't seem to get around this.
I am trying to read the contents of an URL as a string from an URL, But i get a weird
Error -> Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)"
My code :
fetchedString = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:#"www.example.com/iphone"] encoding:NSUTF8StringEncoding error:&error];
NSLog(#"%#",fetchedString);
// if there is something wrong with the URL
if (error) {
NSLog(#"Error -> %#", error);
return ;
}
What am I doing wrong? I tried using getting as NSData as well, but I get null back.
Yes, the URL is missing the scheme: "http://".
"Error -> Error Domain=NSCocoaErrorDomain Code=256"
For the error code check the Apple documentation:
NSError codes in the Cocoa error domain.
NSFileReadUnknownError = 256,
NSFileReadUnknownError
"Read error, reason unknown"
Not that the error definition is very helpful. :-)
Also do not check if error is nil to determine if there is an error, check the return value for nil. error is not guaranteed to be nil on successful execution.
I had a similar problem accessing files located on my device. I followed NSURL isFileURL always returns NO
and used [NSURL fileURLWithPath] instead of [NSURL URLWithString] - this worked!
I got this error (Error Domain=NSCocoaErrorDomain Code=256) as soon as our ssl certificate expired. that may not help you but could help someone else.
Sandboxing
If you're using sandboxing in your app, you might want to check that com.apple.security.network.client is set to YES. It's in the the General tab of your Target in Xcode 5 under
Network: Outgoing Connections (Client)
Also be aware that if you see a code 257 when trying to reach a file:/// url, that's also probably because of sandboxing, but this time rather the File Access part. Because I didn't want to open it to anything else than `com.apple.security.files.user-selected.read-write'
User selected files
I preferred to use A Dead Simple Fileserver and use http://localhost:3000 when in Debug mode.
More reasons that might be causing this specific error:
SSL is misconfigured on the server
The server redirects (301) the http URL to https (see #1)
App transport security also uses this code for blocked requests.
I got the same error. The above marked answer is perfect. But in my case, I had the "http://" in the url but had to add the port number in the url request since there is a service running on a specific port that is actually responding to your request.
#"http://example.com:8084/yyy.zzz"
I got the same error, the above solution didn't work for me, in my case i was calling dataWithContentsOfURL from within a UNNotificationServiceExtension so i had to update the info.plist file of the UNNotificationServiceExtension with the app transport security entries.

NSURLConnection sendSynchronousRequest response is nil upon invalid credential

I'm getting a weird behavior where using sendSynchronousRequest or sendAsynchronousRequest with invalid credential will make the nsurlresponse nil. But the old way with the [[NSURLConnection alloc] initWithRequest:request delegate:self]; I get the 401 response code.
The error value using the sendSynchronousRequest or sendAsynchronousRequest is
Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be
completed. (NSURLErrorDomain error -1012.)" UserInfo=0x756ecb0
{NSErrorFailingURLKey=myurl,
NSErrorFailingURLStringKey=myurl,
NSUnderlyingError=0x75704d0 "The operation couldn’t be completed.
(kCFErrorDomainCFNetwork error -1012.)"
Does someone have a clue as to why it is like that? Any information on this is appreciated. I was expecting to get a 401 response from sendSynchronousRequest or sendAsynchronousRequest
Thanks,
This error is caused when a WWW-Authenticate: HTTP header is returned with the 401 response, asking for user-interaction to enter valid credentials. The NSURLConnection processes the HTTP headers and the response body, returning the response data correctly as an NSData object, but leaving the returningResponse object as nil.
According to Apple's Foundation Constants Reference, the error -1012 is:
NSURLErrorUserCancelledAuthentication
Returned when an asynchronous request for authentication is cancelled by the user.
This is typically incurred by clicking a “Cancel” button in a username/password dialog, rather than the user making an attempt to
authenticate.
I am speculating that it automatically treats the WWW-Authenticate: header as a request for credentials that was cancelled by the user (since it is headless) and generates the error. Then some other part of the code-path that should set the response is not executed because there was an error. Personally I think this is either a bug or bad design. It should be ok to get a valid HTTP response and an error at the same time, either way, you get a valid HTTP response so the returningResponse should be set. Bad Apple!

checkResourceIsReachableAndReturnError always return Domain=NSCocoaErrorDomain Code=4 "The operation couldn’t be completed. (Cocoa error 4.)"

I am trying to use: checkResourceIsReachableAndReturnError of NSURL class
But I always get FALSE and the NSError shows : Domain=NSCocoaErrorDomain Code=4 "The operation couldn’t be completed. (Cocoa error 4.)"
I checked the URL with safary and it works, any idea?
This is not the method you are looking for. The description of the method in NSURL's class reference states:
Returns whether the resource pointed to by a file URL can be reached.
The method should be used to test reachability of file URLs, you cannot check whether an internet resource is available or not using this method.
You'll find several answers in stack overflow if you search for reachability testing or something similar.. However, you could probably just attempt to reach the URL and handle the error if that fails.

Error opening Modal view: "The URL can't be shown"

This is the error that appears in the console:
[WARNING] Modal webview error: Error Domain=WebKitErrorDomain Code=101
"The URL can’t be shown" UserInfo=0x8fee7e0
{NSErrorFailingURLKey=http%3A%2F%2Fimgur.com%2F59tSD.jpg,
NSErrorFailingURLStringKey=http%3A%2F%2Fimgur.com%2F59tSD.jpg,
NSLocalizedDescription=The URL can’t be shown}
I get the same error when loading a local file with:
forge.tabs.open('about.html');
In the former case it looks like you need to decode your url decodeURIComponent
In the later, you need to get the full path to the local file using forge.tools.getURL
This should work:
forge.tools.getURL('about.html', function(url) {
forge.tabs.open(url);
});

Resources