I'm working on the CS193p coursework from Stanford (I'm not a Stanford student I'm just trying to learn), assignment number 5, where we have to get images from Flickr using calls to the Flickr api. I'm only trying to download a list of the pictures and print them out to the console, but I'm getting an NSURLErrorDomain with code -1005. The error message I am printing out is below:
error: Error Domain=NSURLErrorDomain Code=-1005 "The operation couldn’t be completed. (NSURLErrorDomain error -1005.)" UserInfo=0x7f9449c83df0 {NSErrorFailingURLStringKey=https://api.flickr.com/services/rest/?method=flickr.places.getTopPlacesList&place_type_id=7&format=json&nojsoncallback=1&api_key=4f9c3155b34836b2ac15318d98b93f3a, NSErrorFailingURLKey=https://api.flickr.com/services/rest/?method=flickr.places.getTopPlacesList&place_type_id=7&format=json&nojsoncallback=1&api_key=4f9c3155b34836b2ac15318d98b93f3a, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=57, NSUnderlyingError=0x7f9449c7fca0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1005.)"}
The Flickr API call is happening in the following method:
NSURLSession *urlSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]];
NSURLSessionDownloadTask *downloadTask = [urlSession downloadTaskWithURL:[FlickrFetcherHelper URLforTopPlaces] completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
NSArray *topPlaces;
if (!error) {
topPlaces = [[NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfURL:location] options:0 error:&error] valueForKeyPath:FLICKR_RESULTS_PLACES];
}
dispatch_async(dispatch_get_main_queue(), ^{
completionHandler(topPlaces, error);
});
}];
[downloadTask resume];
I'm using xCode 6, not sure if that has anything to do with the problem. The same code was working a couple days ago, and I don't think I changed anything that would mess it up, but it clearly has.
Are you using the iOS8 (iPhone 6 for example) simulator? If so, try changing to iPhone 5s. I was having the same problem and switched my simulator and all worked well again. I tried this after reading the following feedback: https://github.com/AFNetworking/AFNetworking/issues/2314
Switch to iOS Simulator and do "Reset Content and Settings ..." from top menu.
Related
I'm creating a watch application which records an audio and play that audio. The recorded audio is saved in the Apps Groups and I used the following code for playing the audio.
- (void)playAudio
{
// Playing the audio from the url using the default controller
[self presentMediaPlayerControllerWithURL:self.audioFileURL options:#{WKMediaPlayerControllerOptionsAutoplayKey : #YES} completion:^(BOOL didPlayToEnd, NSTimeInterval endTime, NSError * _Nullable error) {
NSLog(#"Error = %#",error);
}];
}
Unfortunately I am getting the following error and the player controller get dismissed immediately.
Error Domain=com.apple.watchkit.errors Code=4 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (1), NSUnderlyingError=0x16daa810 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}, NSLocalizedDescription=The operation could not be completed}.
Then I downloaded a sample project (WatchKitAudioRecorder Sample code) from Apple WatchOS Developer library but they are also having the same issue. I don't know why this is not working even in Apple Sample code :(
Finally I found that the data is not writing to the url path. Also should be written in the following path: Library/Caches/filename.extension
Here is a sample code, which may help someone.
- (void)writeAudioToAppGroupsWithData:(NSData *)audioData
{
// Writing the audio data to the App Groups
NSURL *containerURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:APP_GROUP_IDENTIFIER];
containerURL = [containerURL URLByAppendingPathComponent:[NSString stringWithFormat:DIRECTORY_PATH]];
[audioData writeToURL:containerURL atomically:YES];
}
In this case make sure that your DIRECTORY_PATH is Library/Caches/filename.extension. Eg: Library/Caches/Audio.mp3
I am using NSURLSessionDownloadTask to pull down a simple text file from my goDaddy server using the following code:
-(void)getTheInternetFile
//Fire up the downloadTask to pull the file down from my web server.
NSURLSessionDownloadTask *getTheFile = [session downloadTaskWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.myserver.com/utility/file.txt"]]
completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error)
{
if(error)
{
NSLog(#"Can't do what I want as we have an error %#", [error localizedDescription]);
}
else
{
NSLog(#"It worked");
}
}];
[getTheInternetFile resume];
}
The problem I am having is that this works really well...sometimes. Other times I get an error message that states: "A server with the specified hostname could not be found".
As the URL is hard coded and never changes, I am at a loss to how this can even happen. Unless goDaddy is letting me down, and the server has all of a sudden become unavailable part of the time, I am at a loss. For what it's worth this just started acting this way today, so maybe it is goDaddy.
So it turns out it was goDaddy's server having issues, despite their website reporting that there were none. It took 15 minutes on hold to find out that my code is fine.
I am trying to post message to Tumblr through iOS app
written below code getting error.
NSDictionary *parameters = [[NSDictionary alloc] initWithObjectsAndKeys:
#"Titulo",#"title",
#"Este es el body",#"body",nil];
[[TMAPIClient sharedInstance] post:#"blogName" type:#"text" parameters:parameters callback:^(id var, NSError *error){
NSLog(#"Error %#",error);
}];
getting following error
Error Domain=Request failed Code=401 "The operation couldn’t be completed. (Request failed error 401.)"
This is because you are not authenticated by Tubmlr.
You can refer to it here.
Unable to post a photo using the Tumblr SDK example
I'm trying to download a small file, about 5.5kb.
Half of the time it only downloads half of the json, and then of course fails parsing that data. The other half of the time everything works completely normal.
I have a good internet connection.
Im using AFNetworking 2.0. I got it off of the main branch today (1/16/2014).
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:[NSString stringWithFormat:#"%#Physicians/Types/?os=1",BaseUrl] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(#"JSON: %#", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(#"Error: %#", error);
NSLog(#"Error: %#", operation.responseString);
}];
Here is the exact error, but i already know its a parsing error:
Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (No string key for value in object around character 4480.) UserInfo=0x15ecd010 {NSDebugDescription=No string key for value in object around character 4480.}
This is the sample from their website. And like I said it works half of the time.
Do I need to set some sort of chunk size? Is it because their Github page says the current build is failing?
Interestingly enough, it seems to always fail at the exact same point in the file. I can tell this because in the error, I output the response string.
I am not able to reproduce this in any browser, or in my old app which used asihttprequest
***Update 1/28/2014
I downloaded the current version today, which is passing build, and it still fails. When I save out to disk what it does receive it's 5,391 bytes. Again, it fails at the same point each time. In the middle of the work dentist. There aren't any weird characters there.
I have this code here which sometimes works. I make sure that I am connected to the internet before attempting this Get from Twitter, and I am pretty sure it isn't the problem.
...
NSString *twitterURLString = [NSString stringWithFormat:#"https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=twitterapi&count=2"];NSURL *url = [NSURL URLWithString:twitterURLString];
NSError *error = nil;
NSData *dataFromURL = [NSData dataWithContentsOfURL:url
options:0
error:&error];
NSLog(#"%#", error);
...
This returns the following :
Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)" UserInfo=0x4f6520 {NSURL=https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=twitterapi&count=2}
I'm sure it has to do with the url encoding or something since the actual link works well. Also, it actually works sometime, with the same internet connexion (which I repeat is tested and works fine). Any ideas would be greatly appreciated!