iPhone 自己的数据格式

发布于 2024-08-26 02:08:54 字数 390 浏览 10 评论 0原文

我想为 iPhone 应用程序创建自己的数据格式。这些文件的结构应与 Apple 的 iWork 文件 (.pages) 类似。这意味着,我有一个包含一些文件的文件夹:

The file 'Juicy.fruit' contains:
   Fruits
   ---> Apple.xml
   ---> Banana.xml
   ---> Pear.xml
   ---> PreviewPicture.png

这个文件夹“Fruits”应该打包在一个方便的文件“Juicy.fruit”中。压缩是没有必要的。我怎样才能做到这一点?我发现了一些开源 ZIP 库。然而,我想用 iPhone 的内置库构建我自己的数据格式(如果可能的话)。

此致, 斯特凡

I would like to create my own data format for an iPhone app. The files should be similar structured as e.g. Apple's iWork files (.pages). That means, I have a folder with some files in it:

The file 'Juicy.fruit' contains:
   Fruits
   ---> Apple.xml
   ---> Banana.xml
   ---> Pear.xml
   ---> PreviewPicture.png

This folder "Fruits" should be packed in a handy file 'Juicy.fruit'. Compression isn't necessary. How could I achieve this? I've discovered some open source ZIP-libraries. However, I would like to to build my own data format with the iPhones built-in libs (if possible).

Best regards,
Stefan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏日浅笑〃 2024-09-02 02:08:54

好的,我可以通过三种方式阅读您的问题,这是我对每种方式的最佳猜测:

  1. 您希望您的 .fruit 文件通过 Safari/SMS/某些网络连接(又名当有人想要下载为您的应用程序制作的文件或由您的应用程序制作的文件时)。

在这种情况下,您可以为您的应用程序注册协议,如下所述:

iPhone 文件扩展名应用程序关联

  1. 您希望 iPhone 将 .fruit 文件与您的应用程序全局关联,在这种情况下,您需要查看 统一类型标识符。基本上,您在安装程序的 info.plst 文件中设置此关联。

  2. 您想知道如何从一个包含文件的文件夹转变为该文件夹成为带有 .fruit 扩展名的单个文件(包)。

如果是这样的话,那么有很多选择,我看不出自己推出自己的选择有什么意义。 Microsoft 和 Adob​​e 都只是使用标准的 zip 压缩方法并使用自己的扩展名(而不是 .zip)。如果您将任何 Office 2007 文档(例如 docx 或 Adob​​e 的实验性 .pdfxml 文件)放入存档实用程序中(我喜欢 7z,但任何后裔都可以),您将获取一个包含多个 xml 文件的文件夹,就像您所描述的情况一样。 (这也是 Java 的 jar 文件类型的工作原理,仅供参考)。因此,除非您有充分的理由避免使用标准压缩方法(我投票 gzip),否则我会遵循这一行业的领先做法。

我绝对可以理解在每个可能的级别上进行 DIY 的冲动,但您基本上是在问(如果是#3)如何创建自己的打包算法,并且在阅读了一些最基本的压缩方法的工作原理之后,我会别管那个人了。另外,我真的怀疑苹果是否内置了库来完成大多数人只会使用标准方法的事情。

最后一点:

如果您真的想从头开始(仍然建议不要),因为您的文件都是 XML,您可以创建一个新的 XML 文件,该文件将充当某种包装器,并将每个文件放入那个包装文件。但是,当需要解开包装时,这确实是多余的,因为每次都必须加载整个文件。但它会是这样的:

Juicy.fruit --
   <fruit-wrapper>
       <fruit>
          <apple>
              ... content from apple.xml
          </apple>
       </fruit>
       <fruit>
          <banana>
              ... content from banana.xml
          </banana>
       </fruit>
       <fruit>
          <pear>
              ... content from pear.xml
          </pear>
       </fruit>
       <picture>
              ...URL-encoded binary of preview picture
       </picture>
   </fruit-wrapper>     

但有了这个想法,你要么必须选择解压它,从而冒着失去文件跟踪、覆盖一些但不是全部等等的风险,要么你总是把它当作一个大文件,在在这种情况下,与存档不同,您每次都必须加载所有数据才能提取任何内容,而不是仅从存档中提取所需的文件。

但如果你有决心的话,它可能会起作用。

另外,如果您有兴趣,有一个专门用于移动 XML 的传输协议,称为 WBXML(Wap 二进制 XML)。不确定它是否仍然被认真对待,但如果有一个 iPhone 库,你应该研究一下。

Okay, so there are three ways I am reading your question, here's my best guess on each one:

  1. You want your .fruit files to be associated with your app via Safari/SMS/some network connection (aka when someone wants to download files made for your app or made by your app).

In this case, you can register a protocol for your app, as discussed here:

iPhone file extension app association

  1. You want the iPhone to globally associate .fruit files with your app, in which case you want to look into Uniform Type Identifiers. Basically, you set up this association in your installer's info.plst file.

  2. You want to know how you can go from having a folder with files in it to that folder being a single file (package) with your .fruit extension.

If that's the case, there are many options out there and I don't see a purpose in rolling your own. Both Microsoft and Adobe simply use a standard zip compression method and use their own extension (instead of .zip). If you drop any office 2007 document, such as docx or Adobe's experimental .pdfxml file into an archive utility (I like 7z, but any descent one will do), you will get a folder with several xml files, just like you're describing for your situation. (This is also how Java's jar file type works, fyi). So unless you have a great reason to avoid standard compression methods (I vote gzip), I would follow the industry lead on this one.

I can definitly appreciate the urge to go DIY at every level possible, but you're basically asking (if it's #3) how you can create your own packaging algorithm, and after reading how some of the most basic compression methods work, I would leave that one alone. Plus I really doubt that Apple has built in libraries for doing something that most people will just use standard methods for.

One last note:

If you are really gunning to do it from scratch (still suggest not), since your files are all XML, you could just create a new XML file that will act as a wrapper of sorts, and have each file go into that wrapper file. But this would be really redundant when it came time to unwrap, as it would have to load the whole file every time. But it would be something like:

Juicy.fruit --
   <fruit-wrapper>
       <fruit>
          <apple>
              ... content from apple.xml
          </apple>
       </fruit>
       <fruit>
          <banana>
              ... content from banana.xml
          </banana>
       </fruit>
       <fruit>
          <pear>
              ... content from pear.xml
          </pear>
       </fruit>
       <picture>
              ...URL-encoded binary of preview picture
       </picture>
   </fruit-wrapper>     

But with this idea, you either have to choose to unpack it, and thus risk losing track of the files, overwriting some but not all, etc etc, or you always treat it like one big file, in which case, unlike with archives, you have to load all of the data each time to pull anything out, instead of just pulling the file you want from the archive.

But it could work, if you're determined.

Also, if you are interested, there is a transfer protocol intended specifically for XML over mobile called WBXML (Wap Binary XML). Not sure if it is still taken seriously, but if there is an iPhone library for it, you should research it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文