Mac OS X Lion専用のObjective-Cアプリで作業しています。私はアドレスブックからドラッグを受け入れることを試みています&滴。ライオンのように見えますが、アドレス帳のvCard表現はデータを返さない。残念ながら、前のOSでコードをテストすることはできませんが、以前は可能だったというサンプルコードが見つかりました。Appleのアドレス帳からMac OS X LionのアプリにvCardをドラッグできない
私のテーブルには、ドキュメントが10.6+のようにkUTTypeVCard
を受け取るようにセットアップされています(しかし、NSVCardPboardType
も同様です)。私はドロップイベントを受け取ります。ドロップからのデータの種類とその値を出力するループのデバッグIのセットアップにそれほど:
- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation
{
NSPasteboard *pb = [info draggingPasteboard];
NSArray *types = pb.types;
for (NSString *type in types)
{
NSLog(@" ");
NSLog(@"%@:", type);
NSLog(@" property list = %@", [pb propertyListForType:type]);
NSLog(@" data = %@", [pb dataForType:type]);
NSLog(@" string = %@", [pb stringForType:type]);
}
NSLog(@" ");
return YES;
}
次のような結果は次のとおりです。
2012-02-01 19:46:18.907 MyAppName[586:60b]
2012-02-01 19:46:18.907 MyAppName[586:60b] dyn.ah62d4rv4gu8ycuwftb2gc5xeqzwfg3pqqzv1k4ptr3m1k6xmr3xyc6xwqf6zk8puqy:
2012-02-01 19:46:18.909 MyAppName[586:60b] property list = (null)
2012-02-01 19:46:18.911 MyAppName[586:60b] data = (null)
2012-02-01 19:46:18.912 MyAppName[586:60b] string = (null)
2012-02-01 19:46:18.913 MyAppName[586:60b]
2012-02-01 19:46:18.913 MyAppName[586:60b] ABExpandedSelectionStringArrayType:
2012-02-01 19:46:18.914 MyAppName[586:60b] property list = (null)
2012-02-01 19:46:18.914 MyAppName[586:60b] data = (null)
2012-02-01 19:46:18.915 MyAppName[586:60b] string = (null)
2012-02-01 19:46:18.915 MyAppName[586:60b]
2012-02-01 19:46:18.915 MyAppName[586:60b] dyn.ah62d4rv4gu8ycuwxqz0gn25yrf106y5ysmy0634bsm3gc8nytf2gn:
2012-02-01 19:46:18.917 MyAppName[586:60b] property list = (null)
2012-02-01 19:46:18.918 MyAppName[586:60b] data = (null)
2012-02-01 19:46:18.918 MyAppName[586:60b] string = (null)
2012-02-01 19:46:18.918 MyAppName[586:60b]
2012-02-01 19:46:18.919 MyAppName[586:60b] ABSelectionStringArrayType:
2012-02-01 19:46:18.919 MyAppName[586:60b] property list = (null)
2012-02-01 19:46:18.921 MyAppName[586:60b] data = (null)
2012-02-01 19:46:18.922 MyAppName[586:60b] string = (null)
2012-02-01 19:46:18.922 MyAppName[586:60b]
2012-02-01 19:46:18.922 MyAppName[586:60b] dyn.ah62d4rv4gu8yc6durvwwa3xmrvw1gkdusm1044pxqyuha2pxsvw0e55bsmwca7d3sbwu:
2012-02-01 19:46:18.922 MyAppName[586:60b] property list = (
vcf
)
2012-02-01 19:46:18.923 MyAppName[586:60b] data = <3c3f786d 6c207665 7273696f 6e3d2231 2e302220 656e636f 64696e67 3d225554 462d3822 3f3e0a3c 21444f43 54595045 20706c69 73742050 55424c49 4320222d 2f2f4170 706c652f 2f445444 20504c49 53542031 2e302f2f 454e2220 22687474 703a2f2f 7777772e 6170706c 652e636f 6d2f4454 44732f50 726f7065 7274794c 6973742d 312e302e 64746422 3e0a3c70 6c697374 20766572 73696f6e 3d22312e 30223e0a 3c617272 61793e0a 093c7374 72696e67 3e766366 3c2f7374 72696e67 3e0a3c2f 61727261 793e0a3c 2f706c69 73743e0a>
2012-02-01 19:46:18.923 MyAppName[586:60b] string = <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string>vcf</string>
</array>
</plist>
2012-02-01 19:46:18.923 MyAppName[586:60b]
2012-02-01 19:46:18.923 MyAppName[586:60b] Apple files promise pasteboard type:
2012-02-01 19:46:18.923 MyAppName[586:60b] property list = (
vcf
)
2012-02-01 19:46:18.924 MyAppName[586:60b] data = <3c3f786d 6c207665 7273696f 6e3d2231 2e302220 656e636f 64696e67 3d225554 462d3822 3f3e0a3c 21444f43 54595045 20706c69 73742050 55424c49 4320222d 2f2f4170 706c652f 2f445444 20504c49 53542031 2e302f2f 454e2220 22687474 703a2f2f 7777772e 6170706c 652e636f 6d2f4454 44732f50 726f7065 7274794c 6973742d 312e302e 64746422 3e0a3c70 6c697374 20766572 73696f6e 3d22312e 30223e0a 3c617272 61793e0a 093c7374 72696e67 3e766366 3c2f7374 72696e67 3e0a3c2f 61727261 793e0a3c 2f706c69 73743e0a>
2012-02-01 19:46:18.924 MyAppName[586:60b] string = <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string>vcf</string>
</array>
</plist>
2012-02-01 19:46:18.924 MyAppName[586:60b]
2012-02-01 19:46:18.925 MyAppName[586:60b] dyn.ah62d4rv4gu8ycuwuqz11a5dfnzeyk64uqm10c6xenv61a3k:
2012-02-01 19:46:18.925 MyAppName[586:60b] property list = (
"C9786D5F-157A-4A65-A95E-C61752D2B4E3:ABPerson"
)
2012-02-01 19:46:18.925 MyAppName[586:60b] data = <3c3f786d 6c207665 7273696f 6e3d2231 2e302220 656e636f 64696e67 3d225554 462d3822 3f3e0a3c 21444f43 54595045 20706c69 73742050 55424c49 4320222d 2f2f4170 706c652f 2f445444 20504c49 53542031 2e302f2f 454e2220 22687474 703a2f2f 7777772e 6170706c 652e636f 6d2f4454 44732f50 726f7065 7274794c 6973742d 312e302e 64746422 3e0a3c70 6c697374 20766572 73696f6e 3d22312e 30223e0a 3c617272 61793e0a 093c7374 72696e67 3e433937 38364435 462d3135 37412d34 4136352d 41393545 2d433631 37353244 32423445 333a4142 50657273 6f6e3c2f 73747269 6e673e0a 3c2f6172 7261793e 0a3c2f70 6c697374 3e0a>
2012-02-01 19:46:18.926 MyAppName[586:60b] string = <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string>C9786D5F-157A-4A65-A95E-C61752D2B4E3:ABPerson</string>
</array>
</plist>
2012-02-01 19:46:18.926 MyAppName[586:60b]
2012-02-01 19:46:18.926 MyAppName[586:60b] ABPeopleUIDsPboardType:
2012-02-01 19:46:18.927 MyAppName[586:60b] property list = (
"C9786D5F-157A-4A65-A95E-C61752D2B4E3:ABPerson"
)
2012-02-01 19:46:18.927 MyAppName[586:60b] data = <3c3f786d 6c207665 7273696f 6e3d2231 2e302220 656e636f 64696e67 3d225554 462d3822 3f3e0a3c 21444f43 54595045 20706c69 73742050 55424c49 4320222d 2f2f4170 706c652f 2f445444 20504c49 53542031 2e302f2f 454e2220 22687474 703a2f2f 7777772e 6170706c 652e636f 6d2f4454 44732f50 726f7065 7274794c 6973742d 312e302e 64746422 3e0a3c70 6c697374 20766572 73696f6e 3d22312e 30223e0a 3c617272 61793e0a 093c7374 72696e67 3e433937 38364435 462d3135 37412d34 4136352d 41393545 2d433631 37353244 32423445 333a4142 50657273 6f6e3c2f 73747269 6e673e0a 3c2f6172 7261793e 0a3c2f70 6c697374 3e0a>
2012-02-01 19:46:18.937 MyAppName[586:60b] string = <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string>C9786D5F-157A-4A65-A95E-C61752D2B4E3:ABPerson</string>
</array>
</plist>
2012-02-01 19:46:18.937 MyAppName[586:60b]
2012-02-01 19:46:18.937 MyAppName[586:60b] public.vcard:
2012-02-01 19:46:18.942 MyAppName[586:60b] property list = (null)
2012-02-01 19:46:18.944 MyAppName[586:60b] data = (null)
2012-02-01 19:46:18.945 MyAppName[586:60b] string = (null)
2012-02-01 19:46:18.945 MyAppName[586:60b]
2012-02-01 19:46:18.945 MyAppName[586:60b] Apple VCard pasteboard type:
2012-02-01 19:46:18.945 MyAppName[586:60b] property list = (null)
2012-02-01 19:46:18.946 MyAppName[586:60b] data = (null)
2012-02-01 19:46:18.946 MyAppName[586:60b] string = (null)
2012-02-01 19:46:18.948 MyAppName[586:60b]
2012-02-01 19:46:18.949 MyAppName[586:60b] dyn.ah62d4rv4gu8z82xqqz1gk3penm11swpsqvw1u3px:
2012-02-01 19:46:18.949 MyAppName[586:60b] property list = (null)
2012-02-01 19:46:18.949 MyAppName[586:60b] data = <040b7374 7265616d 74797065 6481e803 84014084 8484114e 534d7574 61626c65 496e6465 78536574 0084840a 4e53496e 64657853 65740084 84084e53 4f626a65 63740085 84014901 96817c01 960186>
2012-02-01 19:46:18.949 MyAppName[586:60b] string = (null)
2012-02-01 19:46:18.949 MyAppName[586:60b]
2012-02-01 19:46:18.950 MyAppName[586:60b] _blendedRowIndexes:
2012-02-01 19:46:18.950 MyAppName[586:60b] property list = (null)
2012-02-01 19:46:18.950 MyAppName[586:60b] data = <040b7374 7265616d 74797065 6481e803 84014084 8484114e 534d7574 61626c65 496e6465 78536574 0084840a 4e53496e 64657853 65740084 84084e53 4f626a65 63740085 84014901 96817c01 960186>
2012-02-01 19:46:18.950 MyAppName[586:60b] string = (null)
2012-02-01 19:46:18.950 MyAppName[586:60b]
2012-02-01 19:46:18.950 MyAppName[586:60b] com.apple.pasteboard.promised-file-content-type:
2012-02-01 19:46:18.951 MyAppName[586:60b] property list = public.vcard
2012-02-01 19:46:18.951 MyAppName[586:60b] data = <7075626c 69632e76 63617264>
2012-02-01 19:46:18.951 MyAppName[586:60b] string = public.vcard
2012-02-01 19:46:18.952 MyAppName[586:60b]
2012-02-01 19:46:18.952 MyAppName[586:60b] com.apple.pasteboard.promised-file-url:
2012-02-01 19:46:18.954 MyAppName[586:60b] property list = (null)
2012-02-01 19:46:18.954 MyAppName[586:60b] data = <>
2012-02-01 19:46:18.954 MyAppName[586:60b] string =
2012-02-01 19:46:18.955 MyAppName[586:60b]
2012-02-01 19:46:18.955 MyAppName[586:60b] dyn.ah62d4rv4gu8y6y4usm1044pxqzb085xyqz1hk64uqm10c6xenv61a3k:
2012-02-01 19:46:18.955 MyAppName[586:60b] property list = (null)
2012-02-01 19:46:18.956 MyAppName[586:60b] data = <>
2012-02-01 19:46:18.956 MyAppName[586:60b] string =
2012-02-01 19:46:18.956 MyAppName[586:60b]
2012-02-01 19:46:18.956 MyAppName[586:60b] NSPromiseContentsPboardType:
2012-02-01 19:46:18.956 MyAppName[586:60b] property list = (null)
2012-02-01 19:46:18.957 MyAppName[586:60b] data = <>
2012-02-01 19:46:18.957 MyAppName[586:60b] string =
2012-02-01 19:46:18.957 MyAppName[586:60b]
タイプのほとんどはプライベートアドレス帳のデータ型のように見えます。しかし、あなたはvCardの表現がnullであることがわかります。私はABPeopleUIDsPboardType
を使ったとしても、それがどのヘッダーファイルでも利用できないので、App Storeから拒否されると考えています。
ドラッグを扱う方法の提案& Lionのアドレス帳からのドロップ?
ありがとうございました。
*編集2/5/12 *
約束したドラッグと約束した内容を研究し、まだ空まで来てみました:
- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation
{
NSPasteboard *pb = [info draggingPasteboard];
// Supposed to call this before readFileContentsType:toFile: for some reason
NSArray *types = pb.types;
NSString *destPath = NSTemporaryDirectory();
NSURL *destURL = [NSURL fileURLWithPath:destPath isDirectory:YES];
NSArray *fileNames = [info namesOfPromisedFilesDroppedAtDestination:destURL];
NSLog(@"fileNames = %@", fileNames);
NSString *afile = [pb readFileContentsType:nil toFile:@"random_filename"];
// Tried with (NSString *)kUTTypeVCard as well, same results
NSLog(@"afile = %@", afile);
// What do I do with this result?
NSString *card = [NSString stringWithContentsOfFile:afile];
NSLog(@"card = %@", card);
NSFileWrapper *wrapper = [pb readFileWrapper];
NSLog(@"wrapper = %@", wrapper);
return YES;
}
結果:
2012-02-05 12:36:58.419 MyAppName[3650:60b] fileNames = (null)
2012-02-05 12:36:58.419 MyAppName[3650:60b] afile = random_filename
2012-02-05 12:36:58.419 MyAppName[3650:60b] card = (null)
2012-02-05 12:36:58.420 MyAppName[3650:60b] wrapper = (null)
ありがとう!明らかに私は* NSFilesPromisePboardType'をすべて登録しました。ドラッグが受信されているため、登録されているデータの種類に気づいていなかったので、登録されたデータの種類を確認しませんでした。私はそのタイプのために登録し、私のコードとあなたはうまくいった –
実際に、私はちょうど私が私のデバッグコードを削除すると、それはうまく動作することを発見した。明らかに、各タイプのデータを出力すると、約束したファイルは無効になります。だから、デバッグのすべてが実際に値を取得することを妨げていました。 –