2011-06-28 17 views
0

私はpdfファイルで動作するアプリを持っています。私はのUITableViewControllerを持っていると(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPathで、私はCFBundleTypeIconFilesにアイコンでcell.imageView.imageを設定したい私のアプリで実行時にCFBundleTypeIconFiles情報を取得するにはどうすればよいですか?

<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> 

が、私はこのアイコンを取得する方法がわからない:私は、ファイルのInfo.plistでこれを追加しました。
docInteractionController.iconsで試しましたが、この配列ではデフォルトのアイコンしか見つかりませんでした。

答えて

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; 
      } 
     } 
    } 
+0

答えてくれてありがとう!しかし、複数のドキュメントタイプがある場合は、たとえば、pdfドキュメントのCFBundleIconFileとjpgドキュメントのCFBundleIconFileを区別する方法があります。 – Giorgio

+0

その他のドキュメントタイプ1つのアプリにつき1つのInfo.plistが必要です。 – steipete

関連する問題