开发者

How to download text file from web on iPhone? [closed]

开发者 https://www.devze.com 2022-12-21 01:46 出处:网络
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so i开发者_开发百科t focuses on one problem only b
Closed. This question needs to be more focused. It is not currently accepting answers.

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 question

I'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

0

精彩评论

暂无评论...
验证码 换一张
取 消