首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何注册应用程序以在ipad的应用程序中打开pdf文件

如何注册应用程序以在ipad的应用程序中打开pdf文件
EN

Stack Overflow用户
提问于 2010-06-04 20:54:46
回答 3查看 18.1K关注 0票数 18

我想在我的应用程序中从pdf页面打开pdf文件,但我没有在我的应用程序中打开pdf的任何选项。

这是我的info.plist文件

 <key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
    <key>CFBundleTypeName</key>
    <string>PDF</string>
    <key>CFBundleTypeRole</key>
            <string>Viewer</string>     
    <key>CFBundleTypeIconFiles</key>
    <string>Icon.png</string>
    <key>LSItemContentTypes</key>
    <string>com.neosofttech.pdf</string>
    <key>LSHandlerRank</key>
    <string>Owner</string>
</dict>
</array>
<key>UTExportedTypeDeclarations</key>
   <array>
   <dict>
    <key>UTTypeConformsTo</key>
        <array>

<string>public.pdf</string>       
         </array>
    <key>UTTypeDescription</key>
    <string>PDFReader File</string>
    <key>UTTypeIdentifier</key>
    <string>com.neosofttech.pdf</string>
    <key>UTTypeTagSpecification</key>
    <dict>
        <key>public.filename-extension</key>
        <string>pdf</string>

    </dict>
</dict>

请告诉我我哪里错了,我如何在我的应用程序中打开pdf文件。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-06-15 13:53:29

我假设你正在尝试根据你的plist在Mail中打开一个附件。由于您不拥有PDF文件类型,因此不能将其声明为导出类型。您只需将其声明为受支持的文档类型。

例如:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>PDF</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.adobe.pdf</string>
        </array>
    </dict>
</array>

您可以在hereUTCoreTypes.h中找到系统提供的所有内容类型的列表。

当有人打开一个PDF文件并选择你的应用程序时,该文件将被复制到应用程序沙箱中Documents文件夹的Inbox子目录中。然后,您的应用程序将被打开,并且在您的应用程序代理的application:didFinishLaunchingWithOptions:中,您的launchOptions字典将包含一个UIApplicationLaunchOptionsURLKey键,指定沙箱中的文件的URL键,然后您可以使用该键。

票数 51
EN

Stack Overflow用户

发布于 2017-02-08 15:57:50

将下面的代码插入到info.plist

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>"*"</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Unknown</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.data</string>
        </array>
    </dict>
</array>
票数 2
EN

Stack Overflow用户

发布于 2019-05-07 16:33:46

旧帖子-但我在这里登陆也是为了寻找一种方法来传递一个PDF到我的应用程序。

Ashley Clark描述的plist帮助我将我的应用程序注册为可以将PDF文件作为参数的应用程序。他在这一点上+1 :-)

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>PDF</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.adobe.pdf</string>
        </array>
    </dict>
</array>

但是,为了完全实现这一点,我在AppDelegate.m文件中使用了以下方法:

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {

    NSLog(@"sourceApplication: %@", sourceApplication);
    NSLog(@"url: %@", url);

当我运行Safari时打开应用程序,并且有一个我想从那里分享的PDF时,上面的代码就会运行。

在上面,我可以确定哪个应用程序向我的应用程序传递了PDF和指向其位置的URL。

运行时,它输出以下内容:

sourceApplication: com.apple.mobilesafari

url: file:///Users/me/Library/Developer/CoreSimulator/Devices/C395439F-7A0D-434F-8D78-D4615DB643E1/data/Containers/Data/Application/E3B181BC-6075-4F2C-923D-2ECC642DA555/Documents/Inbox/pdf-5.pdf

然后,我可以使用URL打开PDF,并在我的应用程序中随心所欲地处理它。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2974285

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档