我想在我的应用程序中从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文件。
发布于 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>
您可以在here或UTCoreTypes.h
中找到系统提供的所有内容类型的列表。
当有人打开一个PDF文件并选择你的应用程序时,该文件将被复制到应用程序沙箱中Documents
文件夹的Inbox
子目录中。然后,您的应用程序将被打开,并且在您的应用程序代理的application:didFinishLaunchingWithOptions:
中,您的launchOptions
字典将包含一个UIApplicationLaunchOptionsURLKey
键,指定沙箱中的文件的URL键,然后您可以使用该键。
发布于 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>
发布于 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,并在我的应用程序中随心所欲地处理它。
https://stackoverflow.com/questions/2974285
复制相似问题