Quote:
Originally Posted by mwyzq
How to download a music file from the server and save it in my Application?
I just wanna my Application read and play the music. But the problem is : How to edit codes to realize downloading music files in the Application??
I can’t find anything for reference online. Any help will be appreciated! Thanks in advance!!!
|
One point first: You can't save files in your application's bundle (actually inside your app). That is read-only.
To download files to your documents or temporary directory you have a couple of choices.
The easiest is to create an NSURL and use the NSURL method dataWithContentsOfURL. You can then write the resulting NSData object to a file with writeToFile:atomically:. The problem is that the dataWithContentsOfURL call is synchronous. Your app will freeze until it is done, which is not a very good user experience.
The second way to download data from a server is to use NSURLRequest and NSURLConnection to create an async request. That's a little more complicated, and involves setting up a delegate and handling a handful of delegate callbacks. If you do a google search on "NSURLConnection file download" or similar, you should be able to find several async download libraries in open source that you can adapt to your needs.