开发者

NSData's writeToFile method failing with server address

开发者 https://www.devze.com 2022-12-25 19:27 出处:网络
I am trying to write an NSData object to a directory like so; [myData writeToFile:[NSString stringWithFormat:@\"%@/%@.txt\", path, filename] atomically:YES];

I am trying to write an NSData object to a directory like so;

[myData writeToFile:[NSString stringWithFormat:@"%@/%@.txt", path, filename] atomically:YES];

I receive no errors or warnings but I am assuming the write fails because the path variable has the format of afp://10.0.0.20/username/Desktop. I am connected to the networked share.

Do I need to modify the string or take a different approach here?

EDIT: Tried the following approach after recommendation开发者_如何学C but it failed

NSMutableURLRequest *post = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"afp://10.0.0.20/username/Desktop/filename.txt"]];
[post setHTTPMethod: @"POST"];
[post setHTTPBody:horreumImageDataNewThread];
NSURLResponse *response;
NSError *error;
[NSURLConnection sendSynchronousRequest:post returningResponse:&response error:&error];

TIA, Ricky.


Where are you getting the afp path string from? You would normally write to a networked volume by using a path like:

/Volumes/NameOfMountedVolume/path/to/file

Also, you should use the -stringByAppendingPathComponent: method of NSString to concatenate paths:

NSString* fullPath = [path stringByAppendingPathComponent:filename];
0

精彩评论

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