Want to improve this question? Update the question so i开发者_开发百科t focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this questionI'm a young iphone dev who needs to download a .txt file from a web (I got a ftp sever) to update a small database on the device. Anyone could give me an advice of how to do this?
Thanks.
Downloading it (see Downloading to a Predetermined Destination)
NSURLRequest* req = [NSURLRequest requestWithURL:[NSURL URLWithString:@"ftp://myftpserver/path/to/file.txt"]];
Reading it (see String Programming Guide)
float aFloat;
NSScanner *theScanner = [NSScanner scannerWithString:aString];
while ([theScanner isAtEnd] == NO) {
[theScanner scanFloat:&aFloat];
// implementation continues...
}
Updating the Database, it all depends on what you are using for a Database. I would start with the Core Data Overview and SQLite docs
You can use
NSDATA *data = [NSDATA dataWithContentOfURL:@"www.yourserver.com/abc.txt"];
and you can later store it in your documents directory
I think using a NSURLDownload would be better as it is meant for it lol.
all you need: http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLDownload.html#//apple_ref/doc/uid/20001839-BAJEAIEE
精彩评论