开发者

Modifying a file on FTP Server

I have finished the majority of my application that I am working on, but I have run into a problem. Basically, what I wrote streams audio from my server to the iPod and plays it without having to save the file. It has a GUI that allows the user to choose the file they want to listen to, and it works flawlessly.

My problem is that I want to be able to have some sort of a counter that updates every time a user listens to a file. I have a file in the project, "TotalDownloads.txt," that I had planned on using to store the new value and upload back to the server, but when the code executes, nothing changes within that file. I had also tried just declaring the file @"TotalDownloads.txt," but that created a new file in the Macintosh HD named "TotalDownloads.txt."

The two identifiers "//-" and "-//" are to parse the file for the number, when I get this figured out, specifically to isolate the numeric value, should there be any formatting involved. Eventually, I want to have counts for each and every one of the files.

I have no problem with downloading the text file off of the server and reading it into the iPhone, but the problem arises when sending it back. What is the easiest way to 1, make a temporary file text file on the iPhone, and 2, upload it back to the server to replace the existing file?

Is there a way to just modify the file on the开发者_开发百科 server?

Any help is appreciated.

Below is what I have so far:

- (IBAction)action
{
    NSURL *textURL = [NSURL URLWithString:@"http://www.faithlifefellowship.us/Audio/TotalDownloads.txt"];
    NSString *textFromFile = [NSString stringWithContentsOfURL:textURL encoding:NSUTF8StringEncoding error:false];
    int click = [textFromFile intValue];
    click += 1;

    NSString *replace = @"//-";
    NSString *clicks = [NSString stringWithFormat:@"%d",click];
    replace = [replace stringByAppendingString:clicks];
    replace = [replace stringByAppendingString:@"-//"];

    //test is a label I used to check to make sure the download count was being read properly.
    test.text = clicks;

    [replace writeToFile:[[NSBundle mainBundle] pathForResource:@"TotalDownloads" ofType:@"txt"]atomically:YES encoding:NSUTF8StringEncoding error:NULL];
}


Here is the best way I suggest you do this.

  1. Set up a page on your server that accepts a get request.
  2. Code the page to take the value from that get request (which should be the name of the file you are trying to update) and update the file at that path.
  3. From your app, use UIWebView this way:

UIWebView* web = [UIWebView new]; [web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.mydomain.com/myPage.php"]]];

web = nil;

Presto!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜