Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 27, 2011, 03:06 PM   #1
gameplayerxp
macrumors newbie
 
Join Date: Dec 2010
Location: Sydney
Can NSFileManager open remote files?

Hi,

I have couple text files stored on a website and can be accessed via http protocol. Can NSFileManager query and open these files? I tried to construct a URL like this:

Code:
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *onlineURL = [NSURL URLWithString: @"http://www.myweb.com/temp"];
NSError *error = nil;
NSArray *onlineFiles = [fileManager contentsOfDirectoryAtURL:onlineURL includingPropertiesForKeys:[NSArray array] options:0 error:&error];
But seemed that NSFileManager does not work.

Any hints?

Thanks.

-Ray
__________________
New to Mac and iPhone/iPad.
gameplayerxp is offline   0 Reply With Quote
Old Jan 27, 2011, 03:10 PM   #2
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by gameplayerxp View Post
But seemed that NSFileManager does not work.
Does not work how? Please be specific. Are you getting compile-time warnings or errors? What about at run-time? It is crashing? If so, have you checked the crash logs? What debugging have you already done? Etc.
__________________
dejo is offline   0 Reply With Quote
Old Feb 7, 2011, 03:51 PM   #3
gameplayerxp
Thread Starter
macrumors newbie
 
Join Date: Dec 2010
Location: Sydney
Quote:
Originally Posted by dejo View Post
Does not work how? Please be specific. Are you getting compile-time warnings or errors? What about at run-time? It is crashing? If so, have you checked the crash logs? What debugging have you already done? Etc.
The error happens at runt time. "contentsOfDirectoryAtURL" returns nil and error is "The operation couldn’t be completed. (Cocoa error 260.)". I'm running it in the simulator and the internet connection is available.

Btw, is there any way to copy files to simulator? Thanks.
__________________
New to Mac and iPhone/iPad.
gameplayerxp is offline   0 Reply With Quote
Old Feb 7, 2011, 04:30 PM   #4
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by gameplayerxp View Post
The error happens at runt time. "contentsOfDirectoryAtURL" returns nil and error is "The operation couldn’t be completed. (Cocoa error 260.)". I'm running it in the simulator and the internet connection is available.
Sounds like a server-side issue to me. Are you sure that your web server allows you to query a directory remotely? Just kinda guessing here, though.

P.S. Are the files you're accessing static in name? If so, why not access them directly?
__________________
dejo is offline   0 Reply With Quote
Old Feb 7, 2011, 04:33 PM   #5
PhoneyDeveloper
macrumors 68030
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
NSFileManager only works with file URLs.

The iPhone Sim folder hierarchy is inside ~/Library/Application Support/iPhone Simulator. You can manipulate the files in there from the Finder (add, remove, delete, etc.) You can of course print out a full path to a file in your app's sandbox to see exactly where it is on your Mac.
PhoneyDeveloper is offline   0 Reply With Quote
Old Feb 7, 2011, 04:36 PM   #6
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by PhoneyDeveloper View Post
NSFileManager only works with file URLs.
Hmm, why would contentsOfDirectoryAtURL:includingPropertiesForKeysptions:error: be available then?
__________________
dejo is offline   0 Reply With Quote
Old Feb 7, 2011, 04:56 PM   #7
PhoneyDeveloper
macrumors 68030
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
@dejo, I don't really understand what you're asking. For some reason Apple likes referencing file system files as URLs and it's added a bunch of new File System APIs over the past couple years that prefer URLs. But the only URLs that work are file system URLs (file:///path/to/my/file).

The API you mention is one of these new URL APIs.

If I'm wrong you can easily prove it by loading up a remote file. But I don't think it will work.
PhoneyDeveloper is offline   0 Reply With Quote
Old Feb 7, 2011, 04:58 PM   #8
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Ah, so you're saying you can only use that API to access local files and not remote ones. Wow, that's quite the abuse of the U in URL!
__________________
dejo is offline   0 Reply With Quote
Old Feb 12, 2011, 01:10 AM   #9
gameplayerxp
Thread Starter
macrumors newbie
 
Join Date: Dec 2010
Location: Sydney
Quote:
Originally Posted by PhoneyDeveloper View Post
@dejo, I don't really understand what you're asking. For some reason Apple likes referencing file system files as URLs and it's added a bunch of new File System APIs over the past couple years that prefer URLs. But the only URLs that work are file system URLs (file:///path/to/my/file).

The API you mention is one of these new URL APIs.

If I'm wrong you can easily prove it by loading up a remote file. But I don't think it will work.
Then that's what I guess. Thanks
__________________
New to Mac and iPhone/iPad.
gameplayerxp is offline   0 Reply With Quote
Old Feb 12, 2011, 04:16 AM   #10
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
Quote:
Originally Posted by dejo View Post
Ah, so you're saying you can only use that API to access local files and not remote ones. Wow, that's quite the abuse of the U in URL!
See this post
kainjow is offline   0 Reply With Quote
Old Feb 12, 2011, 12:36 PM   #11
PhoneyDeveloper
macrumors 68030
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
OK, that post and the NSURL docs do clarify things somewhat. As of MacOS X 10.6 and iOS 4.0 there have been some additions to NSURL to make it work better with files.

However, quite a number of these new APIs are available on iOS 4.0 and later but not implemented. File reference URLs and bookmarks are unimplemented on iOS. They probably wouldn't be of much use anyway since users don't have direct access to the file system.

File properties moves some functionality from NSFileManager directly into NSURL. That's a kind of distinction without a difference.

The mentioned speed improvements might be useful if true. I don't see any real description of this or even a mention of this in the docs.

I guess we can look forward to a deprecation of NSFileManager methods and NSString methods that deal with files soon. Oh joy.
PhoneyDeveloper is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Can't screenshot, open Skype, delete files, open itunes.... delab99 OS X 12 Dec 19, 2013 02:45 PM
Remote Desktop Connection was open israelcnf OS X Mavericks (10.9) 1 Nov 10, 2013 02:13 AM
Resolved: NSFileManager copyItemAtPath Operation not permitted Tex-Twil iPhone/iPad Programming 14 Sep 25, 2013 09:41 AM
remote access files on the network macbookbie OS X 4 Jul 17, 2012 03:18 PM
Remote upload of files knightmese Mac OS X Server, Xserve, and Networking 0 Jun 4, 2012 06:05 PM

Forum Jump

All times are GMT -5. The time now is 11:37 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC