iPhone从桌面选取文件
我是 Objective C 和 iPhone 编程的初学者。我正在制作一个程序,用于通过 gprs 将文件从 iphone 传输到服务器。我不知道如何从桌面上选择一个文件加载到模拟器中,然后将文件发送到服务器。请解释一下我如何选择这样的文件,我也不知道如何访问文件的路径Mac 操作系统。下面的代码对于获取文件有用吗
NSString *urlStr = @"192.168.178.26";
if (![urlStr isEqualToString:@""]) {
NSURL *website = [NSURL URLWithString:urlStr];
if (!website) {
NSLog(@"%@ is not a valid URL");
return;
}
NSHost *host = [NSHost hostWithName:[website host]];
[NSStream getStreamsToHost:host port:3258 inputStream:&iStream outputStream:&oStream];
[iStream retain];
[oStream retain];
[iStream setDelegate:self];
[oStream setDelegate:self];
[iStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
forMode:NSDefaultRunLoopMode];
[oStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
forMode:NSDefaultRunLoopMode];
[iStream open];
[oStream open];
I am a beginner in objective c and iphone programming. I'm making a program for transfering files from iphone to server through gprs. I dont know that how can i pick a file from the desktop to load into the simulator and then sending the file to the server.please explain that how can i pick such file and i also dont know how to access the path of a file in a mac operating system. Can the following code be useful in picking up a file
NSString *urlStr = @"192.168.178.26";
if (![urlStr isEqualToString:@""]) {
NSURL *website = [NSURL URLWithString:urlStr];
if (!website) {
NSLog(@"%@ is not a valid URL");
return;
}
NSHost *host = [NSHost hostWithName:[website host]];
[NSStream getStreamsToHost:host port:3258 inputStream:&iStream outputStream:&oStream];
[iStream retain];
[oStream retain];
[iStream setDelegate:self];
[oStream setDelegate:self];
[iStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
forMode:NSDefaultRunLoopMode];
[oStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
forMode:NSDefaultRunLoopMode];
[iStream open];
[oStream open];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将需要查看使用文档路径并将项目保存到手机/模拟器应用程序文档文件夹中(ios 不支持用户创建的子文件夹,因此层次结构非常平坦,例外的是 ios 上有一些预定义的位置,您可以放置文件)
下面的示例读取/写入 ios 文件系统。您需要以某种方式传输客户端/服务器。
You will need to look at using Documents path and saving items into the phone/simulators app documents folder (ios does not support user created subfolders so the hierarchies are pretty flat, exceptions being there are a few predefined places on the ios you can put files)
Examples below read/write to ios file system. You would need to transport that somehow client/server.
您可以将测试文件作为资源添加到项目中。
You can add your test file to the project as a resource.