Reputation: 25392
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];
}
Upvotes: 0
Views: 207
Reputation: 25392
Here is the best way I suggest you do this.
UIWebView* web = [UIWebView new];
[web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.mydomain.com/myPage.php"]]];
web = nil;
Presto!
Upvotes: 1