NSURLDownload failing - objective-c

I'm trying to download a file in my cocoa app as follows :
NSURLRequest *downloadRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:downloadURL]];
NSURLDownload *downloader = [[NSURLDownload alloc] initWithRequest:downloadRequest delegate:self];
where downloadURL is something like "https://www.abcd.com/path/to/file/abc.zip"
But I keep getting the following NSError in the (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error method :
Error Domain=NSURLErrorDomain Code=-3001 "The operation couldn’t be
completed. (NSURLErrorDomain error -3001.)" UserInfo=0x618000060a80
{NSErrorFailingURLStringKey=https://www.abcd.com/path/to/file/abc.zip,
NSUnderlyingError=0x618000242010 "The operation couldn’t be completed.
(kCFErrorDomainCFNetwork error -3001.)",
NSErrorFailingURLKey=https://www.abcd.com/path/to/file/abc.zip}
What am I doing wrong?
Thanks for your help!

The error you are receiving is kCFURLErrorCannotOpenFile. You will probably need to capture and deal with the .zip file manually.

I solved the issue.
The NSURLDownload object's setDestination method needs the not just the directory path (/xx/yy/zz), but also the filename (/xx/yy/zz/abc.zip).

Related

objective c load AVAsset from NSFileManager file path

So i download an .mp4 file using
urlData * =[NSData dataWithContentsOfUrl:filePath]
then save it using NSFileManager
[urlData writeToFile:filePath atomically:YES];
this saves the file in the NSFileManager directory just fine I can go into iTunes and see it, open and play the video so I know that part is working.
Here is where it breaks for me. I want to open and play these files, so i use like i use
[AVURLAsset URLAssetWithURL:filePath options:nil];
for some reason this always goes to a state of 'AVPlayerStatusFailed'. When I put a break point in and inspect the error I get 'unknown error'
Error Domain=NSURLErrorDomain Code=-1 "unknown error" UserInfo={NSLocalizedDescription=unknown error, NSUnderlyingError=0x1382f9630 {Error Domain=NSOSStatusErrorDomain Code=-12935 "(null)"}}
what am i missing here? or how can i get a better error than 'unknown error'
ok so as it turns out here is how i should have built the NSURL
[AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:filePath] options:nil];

The operation couldn’t be completed. No such file or directory: but the file exists

I get a weird issue while saving a file with writeToFile:options:error: In the first case I get the following issue:
writeToFile failed with error Error Domain=NSCocoaErrorDomain Code=4 "The file “preferences.plist” doesn’t exist." UserInfo=0xa12c30 {NSFilePath=file:/Users/patrick/Desktop/Untitled.fef/preferences.plist, NSUnderlyingError=0xa0d130 "The operation couldn’t be completed. No such file or directory"}
But the file actually exist in that location. The file is stored in the app document file package.
CODE: (Subclass of NSDocument)
NSString *prefFile = [[[self fileURL] absoluteString] stringByAppendingPathComponent:#"preferences.plist"];
NSError *error;
BOOL succes = [[NSKeyedArchiver archivedDataWithRootObject:documentPreferences] writeToFile:prefFile options:0 error:&error];
if (!succes) {
NSLog(#"writeToFile failed with error %#", error);
}
Make sure when using any of the ...toFilemethods of various classes that you use a real path and not by mistake a file URL. You can tell these apart by looking at the path. If the path starts with file://it can't be used. If it starts with a slash / it is a regular file path. Still you might use NSFileManager to check if the file exists.
As in your code instead of calling absoluteString on self.fileURL call path.

iOS app Share a link on Tumblr

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

setUbiquitous:itemAtURL:destinationURL:error: does not remove the item from iCloud

If I send the message
[[NSFileManager defaultManager] setUbiquitous:NO
itemAtURL:url
destinationURL:iCloudURL
error:&err]
to remove an item from iCloud, it doesn't actually delete the file on the Ubiquitous Container. Is this the expected behaviour?
The method returns NO and the error object contains
Error Domain=NSCocoaErrorDomain Code=512 "The operation couldn’t be
completed. (Cocoa error 512.)"
UserInfo=0x20870970
{NSURL=file://localhost/var/mobile/Applications/168EE8CD-4CDF-49BE-AD88-1DC7DD9CF25F/Documents/test.txt,
NSUnderlyingError=0x20863a00 "The operation couldn’t be completed.
(LibrarianErrorDomain error 2 - Cannot disable syncing on a unsynced
item.)"}
The error is pretty clear. You're trying to delete an item from iCloud that's not in iCloud. When you want to delete an item from iCloud using setUbiquitous:..., the item URL (itemAtURL:) should be the iCloud URL. The destination URL can be something local (but is ignored if ubiquitous is set to NO).
When specifying the "setubiquitous" parameter to "no", your destinationURL needs to be the local url, not the iCloud one. You have your URLs switched
To delete an item on iCloud, you can try this code:
NSError *err;
NSFileCoordinator* fileCoordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
[fileCoordinator coordinateWritingItemAtURL:_url
options:NSFileCoordinatorWritingForDeleting
error:&err
byAccessor:^(NSURL* writingURL) {
NSFileManager* fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtURL:writingURL error:nil];
}];
[fileCoordinator autorelease];
Good luck!

resolving an NSURLErrorCannotOpenFile error

I wrote some code to download a URL to my disk, using an NSURLRequest and an NSURLDownload. The download starts fine (at least, it sends downloadDidBegin:(NSURLDownload *)download), but then it sends
-(void)download:(NSURLDownload *)download didFailWithError:(NSError *)error
My implementation of the function is as follows:
{
[download release];
NSLog(#"Download failed! Error - %# %#",
[error localizedDescription],
[[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
}
The logged error is
2011-07-17 01:48:43.194 URLDownloader[28031:903] Download failed! Error - The operation couldn’t be completed. (NSURLErrorDomain error -3001.) [the URL in the NSURLRequest]
From what I can tell, this is the NSURLErrorCannotOpenFile error. I cannot find any explanation of why this error occurs, other then "Returned when NSURLDownload was unable to open the downloaded file on disk." from the documentation. So, why is this happening?
Fact that might be helpful(?): NSURLErrorCannotOpenFile is enumerated as kCFURLErrorCannotOpenFile. I have no idea what this means either....
Alright, so I was just being foolish. I had created a path using NSURL's absoluteString method instead of the path method. This was just bad coding on my part...