OGeek|极客世界-中国程序员成长平台

标题: ios - 如何在 phonegap build 中使用 iTunes 文件导入/导出功能 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 07:58
标题: ios - 如何在 phonegap build 中使用 iTunes 文件导入/导出功能

我正在使用 apache cordova 和 adobe phonegap build 构建一个小应用程序。

我已经为 html5 文件 api 文件系统添加了 filer.js 包装器,它就像一个魅力。 我可以在应用程序中编写、列出和打开我的文件。

我需要做的是使用 iTunes 和基座电缆(没有 wifi 或互联网可用)检索文件。

我尝试了很多配置,但无法让我的应用出现在我可以从中获取文件的应用列表中。

到目前为止,我的 config.xml 文件配置是:

<feature name="http://api.phonegap.com/1.0/file"/>
<preference name="UIFileSharingEnabled" value="true" />
<preference name="iosPersistentFileLocation" value="Compatibility" />


<key>lugins</key>
    <dict>
        <key>File</key>
        <string>CDVFile</string>
    </dict>

    <key>lugins</key>
    <dict>
        <key>FileTransfer</key>
        <string>CDVFileTransfer</string>
    </dict>

此应用仅适用于 iPad 上的 ios。

任何想法将不胜感激。谢谢



Best Answer-推荐答案


我相信这只能通过 cordova 插件来完成,因为只有插件才能修改 plist 文件。以下是我使用 cordova 4.3.0 所采取的步骤:

  1. 在你的cordova项目之外的某个地方创建你的插件目录,比如说在/home/user/中。该插件只包含一个文件,目录结构如下:

    /home/user/com.mycompany.cordova.itunesfilesharing/
    /home/user/com.mycompany.cordova.itunesfilesharing/plugin.xml
    
  2. 在插件目录下需要plugin.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
        xmlns:android="http://schemas.android.com/apk/res/android"
        id="com.mycompany.cordova.itunesfilesharing"
        version="1.0.0">

    <name>Enable iOS iTunes file sharing in Plist file</name>
    <description>iOS plugin for a custom Plist addition</description>
    <platform name="ios">
        <config-file target="*-Info.plist" parent="UIFileSharingEnabled">
            <true/>
        </config-file>
    </platform>
</plugin>
  1. 那么你需要把这个插件添加到你的cordova项目中:

    cordova plugin add /home/user/com.mycompany.cordova.itunesfilesharing
    

这会将插件复制到您的 cordova 项目中。添加后,您将看到这些已添加到您的 plist 文件中:

<key>UIFileSharingEnabled</key>
<true/>

这就是我所要做的,不需要更改 config.xml。只需添加自定义插件。然后这样的应用程序将允许访问它在 iTunes 中的 Documents 目录。

关于ios - 如何在 phonegap build 中使用 iTunes 文件导入/导出功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23885283/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4