读取 .csv 文件的 iPhone 应用程序
iOS 应用程序可以读取已放置在该设备上的文件(例如 CSV 文件)吗?
因此,我们的想法是,当您在家时,您可以创建包含项目列表的文件,或者在您的 PC 上通过电子邮件发送该文件等,然后将该文件(以正确的格式)放置在读取它的设备上。
这可能吗?
Can an iOS app read a file that has been placed on that device e.g. a CSV file.
So the idea is when you're at home you create the file with a list of items or you get emailed it etc on your PC and then you place this file (in the correct format) on the device which reads it.
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以读取 CSV 数据,但“将文件放置在设备上”必须涉及某种 Web 服务。如果不从 Web 服务器获取数据,就无法将数据添加到应用程序。但是,如果您有一个可以托管 csv 文件的 Web 服务器,那么打开和读取它就相当简单了。
这涵盖了大部分内容
导入 csv 数据 (SDK iphone)
将处理剩下的事情
You can read CSV data but "place the file on the device" would have to involve a web service of some sort. There is no way to add data to an application without getting in a from a web server. But if you have a web server that can host the csv file then opening and reading it is fairly simple.
this covers most o it
Import csv data (SDK iphone)
will take care of the rest
有一个字符串功能可以获取每个值并将其放入数组中:
There is a string feature that will take each value and place it into an array:
您可以在 iOS 设备上解析 CSV。
您可以将数据文件放置在 iOS 设备上。
但请注意 CSV 格式的详细信息。仅在“,”上分割字符串肯定会导致失败和随机错误。看看 http://cocoawithlove.com/2009/11 /writing-parser-using-nsscanner-csv.html 有关如何处理 CSV 数据的一个很好的示例。
我个人非常喜欢使用 cocoa 的示例来创建一个操作,从 http 位置下载 CSV,解析并处理它,然后将结果存储在核心数据存储中。
但您也可以使用 NSURLConnection 在设备上获取 CSV 文件。但请注意:NSURLDownload 在 iOS 上不可用。也不建议将数据下载到设备。 Apple 建议处理数据并存储结果,或者仅根据需要获取数据。
You can parse CSV on an iOS device.
You can place a data file on an iOS device.
Beware though of CSV format details. Just splitting a string on "," is a surefire way to get failures and random errors. Have a look at http://cocoawithlove.com/2009/11/writing-parser-using-nsscanner-csv.html for a good example on how to handle CSV data.
I've personally used the example from cocoa with love to create an operation that downloads a CSV from a http location, parses and processes it and then stores the results in a Core-Data store.
But you could just as well get the CSV file on your device by using an NSURLConnection. Beware though: NSURLDownload is unavailable on iOS. Also downloading data to the device is not recommended. Apple recommends processing the data and storing the results or just getting the data as you need it.