0

我有一个可以处理 pdf 文件的应用程序。我在 Info.plist 文件中添加了这个:

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

在我的应用程序中,我有一个 UITableViewController (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath,我想在cell.imageView.image其中设置图标,CFBundleTypeIconFiles但我不知道如何获取此图标。
我试过了docInteractionController.icons,但在这个数组中我只找到了默认图标。

4

1 回答 1

0

查看 HockeyKit 中的代码,我正是这样做的: https ://github.com/TheRealKerni/HockeyKit/blob/develop/client/iOS/BWHockeyViewController.m

从第 336 行开始:

NSString *iconString = nil;
    NSArray *icons = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIconFiles"];
    if (!icons) {
        iconString = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIconFile"];
        if (!iconString) {
            iconString = @"Icon.png";
        }
    } else {
        BOOL useHighResIcon = NO;
        IF_IOS4_OR_GREATER(if ([UIScreen mainScreen].scale == 2.0f) useHighResIcon = YES;)

        for(NSString *icon in icons) {
            iconString = icon;
            UIImage *iconImage = [UIImage imageNamed:icon];

            if (iconImage.size.height == 57 && !useHighResIcon) {
                // found!
                break;
            }
            if (iconImage.size.height == 114 && useHighResIcon) {
                // found!
                break;
            }
        }
    }
于 2011-08-03T09:48:54.480 回答