Xcode iPhone SDK - Uploading a file
I want to upload a file to a website (In this case MediaFire)
Non-working code i got so far:
NSString *File2upload = @"Documents/data.xml";
NSURL *url = [NSURL URLWithString:@"http://username@hotmail.com:password@mediafire.com/data.xml"];
[File2upload writeToURL:url atomically:YES encoding:开发者_Go百科NSUTF8StringEncoding error: NULL];
Rather than ignore the error (by passing NULL
as the error:
argument), you should take a look at the NSError
object returned by the call. The name of the NSString
method you're calling (writeToURL:atomically:encoding:error:
) may suggest you can use arbitrary schemes, but in fact only file://...
urls will work.
If you want to upload a file to an ftp server, you'll need to use an ftp client library, such as those mentioned in this previous answer.
精彩评论