Uploading Plist to FTP - iphone

I've been googling a lot about this issue, and I just couldn't find the best answer for me.
My program creates plist file from user inputs such like "name", "phone" etc..
While I'm trying to save it to docs, all works fine.
I'm using:
[thePlist writeToFile:thePath atomically:YES];
Now, I want to save it on my FTP server.
I tried this code and it doesn't work:
[plistData writeToURL:[NSURL URLWithString:#"ftp://User:PassWord#DomainName"] atomically:YES];
(P.S. While typing the full address in safari, it is recognized and has no problem to access there, so the address is not the issue here.)
Thank you all for the help!

NSData writeToURL only supports the "file://" scheme. So that will not work.
The best is probably to post the data with http to the server and have code on the server to accept the post.
From Apple's documentation:
The location to which to write the receiver's bytes. Only file:// URLs are supported.
Since at present only file:// URLs are supported, there is no difference between this method and writeToFile:atomically:, except for the type of the first argument.

Related

NSInputStream working with with local file, not with file pulled down from server

Hey guys so I'm pulling down a yaml file from a web server. My NSInputStream works great with local yaml files (using file://filename.yaml url scheme)
Here's the relevant code snippet:
NSInputStream * stream = [[NSInputStream alloc] initWithURL:yamlURL];
Where yaml url is something like http:// myip:8000/assets/test.yaml Opening in a browser just results in file download...
Any thoughts?
Im way too late for this, but i just solved this exact problem, so here goes:
As per the docs,
The NSStream class does not support connecting to a remote host on iOS.
As stupid as this sounds, initWithURL will only work for a local file. But theres an easy fix...
Full explanation and code sample from apple can be found here:
https://developer.apple.com/library/mac/documentation/cocoa/Conceptual/Streams/Articles/NetworkStreams.html#//apple_ref/doc/uid/20002277-BCIDFCDI
Is there anything you're doing with the *stream, After you initWithURL?
If you are taking the content from the InputStream inited with the local file, you would need to be creating a NSOutputStream to take the InputStream and redirect it to Safari. So I don't think just initWithURL: call with the url will tell you much, but the call to open the http:// url in safari will try to determine the content-type and try to output the file. But I don't think safari would be able to display the contents if it was a mulit-part mime yaml file.

how can I save the whole plist data coming from server (without formatting) to another plist

[NSPropertyListSerialization propertyListFromData:self.responseData
mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:&format
errorDescription:&errorDesc];
When the server is online, it sends the responseData. Now I want to save this data(obtained through the responseData in the code) directly to another plist in my app, so that I can retrieve the data later(when the server is offline) in the same format(without changing) and use it/pass it in the same way as it is being passed when my server is online. I am doing this so that the user of the app does not come to know whether the server is online/offline and still is able to give updates/feedback to the responseData (as he/she would give when the server is online). I don't want to break the responseData and save it, rather directly save it the way it is coming from the server.
Please let me know if more explanation is required.And thanks for all the answers that you would be giving :)
If you don't want to change anything I believe you should just download the plist as a file and not as data.
To save the file on the phone you should use NSFileManager, you can read about it here:NSFileManager reference + File System Programming Guide
You must pay attention to the place you save the plist according to apple "new" rules of data storage, you can read about it here:
Were you should save your files
Good luck

Options for transferring file to iPhone/iPad

I'm working on an app and need to add the ability to import CSV files into the app for processing. What are the options here? I've read posts about embedding http servers or fetching a CSV file from a web resource, but what is the easiest way to do this?
thanks
I've used NSData's dataWithContentsOfURL: just recently; it worked fine. Plus there's a convenient writeToFile:atomically: or writeToFile:options:error: message you can send to your data object.

Launch my app using email attachement

I want to bind my app to some file extension so when I receive an email with an attached file with the correct extension, clicking on it will launch my app and pass it the attached file.
Is it possible ? How ?
Thx
--G.
As iPhone applications are not allowed to share files on the file system, what you're looking for is not immediately possible (not with the published APIs that I know of, anyway). You might still have a couple of options though.
Either way you'll have to use a custom URL scheme, which is associated with your app, and paste that into your email. This URL might point to some external location, which your app can download the file from.
Or it might contain the actual file contents if it's fairly small. URLs are 'just text' (some restrictions apply), so you're free to put any data you want to in it, as long as it is URL-encoded.
You still need to get the URL into the email though, which might or might not be as easy as attaching a file.
It's not possible to simply associate a file extension with an application on the iPhone.
You could create a custom URL scheme that would launch your app, but probably that won't help you.
This is actually possible, I'm working on this exact same problem and this great tutorial has really helped me.

Streaming and playing an MP3 stream. .mp3 URL format

I used the sample code from http://cocoawithlove.com/2008/09/streaming-and-playing-live-mp3-stream.html. it runs OK with default URL. But when I replace with my URL "http://dl.mp3.kapsule.info/fsfsdfdsfdserwrwq3/fc90613208cc3f16ae6d6ba05d21880c/4b5244f0/b/7e/b7e80afa18d06fdd3dd9f9fa44b51fc0.mp3?filename=Every-Day-I-Love-You.mp3", this app shows an message as "Audio not Found". But when I put my URL on Address Bar of Web Browser, I can download this .mp3 file.
really, I can't understand why it is?
pleased tell me!
Thank you very much
My guess would be that the app is designed to play a MP3 encoded audio stream with no limit in length (which is different from your ordinary music file). To set this up, you need a streaming server on the client side.
I think you can find out for sure by trying with a different radio station that transmits in MP3. If that works, it's most likely that your app doesn't like your file.
You should, as Vivek recommends, also try using a simpler download URL for your file, in case the App gets confused by the URL's length and/or structure.
As mentioned, this is due to the URL of the file. The AudioStreamer code specifically checks for the extension of the file and tries to figure out the audio type based on that. If you change that logic to handle your custom URLs, it will start working
So to point you in the right direction: open AudioStreamer.m and look for the references of
hintForFileExtension:
This function returns the type of file based on the extension. If you know the file type won't change (always mp3), the quick and dirty solution is to always assign mp3 type without any logic... like this:
err = AudioFileStreamOpen(self, MyPropertyListenerProc, MyPacketsProc, kAudioFileMP3Type, &audioFileStream);
Note: I've put kAudioFileMP3Type constant instead of calculated value
PS yes, it does work with static mp3 files, even though it's designed for streams and hence misses some of the functionality one would expect from a player that plays a static file on the server (caching, prefetching, proper seeking)
Thats because the default url directly points to a file in the webserver, whereas the the url you've mentioned is a HTTP (POST/GET) operation, which the application may not be designed to handle.
I suspect that your URL is one-time-use. When I try to visit it, I see 408 - Request Timeout.
Many links on mass file sharing websites are like this. If you could download the file directly, you wouldn't sit through a page of ads and premium account offers.
Try again with a file on a normal website, like this one.