2012-02-02 11 views
0

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) 

答えて

0

なぜ成功しなかったのか分かりませんが、質問があります。NSFilesPromisePboardTypeのテーブルビューを登録しましたか?それ以外の場合は動作しません! 私は今、テストされ、働く私のアプリ1からコードスニペットが表示されます:

- (BOOL) tableView:(NSTableView *)aTableView 
     acceptDrop:(id <NSDraggingInfo>)info 
       row:(NSInteger)row 
     dropOperation:(NSTableViewDropOperation)operation 
{ 
    NSPasteboard *pboard = [info draggingPasteboard]; 
    NSArray *types = pboard.types; 

    if([types containsObject:NSFilesPromisePboardType]){ 
     NSString *destPath = NSTemporaryDirectory(); // or whatever you want 
     NSURL *destURL = [NSURL fileURLWithPath:destPath isDirectory:YES]; 
     NSLog(@"destURL %@", destURL); 
     NSArray *fileNames = [info namesOfPromisedFilesDroppedAtDestination:destURL]; 
     NSLog(@"fileNames %@", fileNames); 
     if(fileNames == nil) return NO; 
     NSString *resultPath = [destPath stringByAppendingPathComponent:[fileNames objectAtIndex:0]]; 
     NSLog(@"resultPath %@", resultPath); 
     // read the vCard data from here 
     NSString *vCard = [NSString stringWithContentsOfFile:resultPath 
                encoding:NSASCIIStringEncoding 
                 error:NULL]; 
     NSLog(@"vCard =\n%@", vCard); 
     return YES; 
    } 
    return NO; 
} 

テスト出力があるが、

destURL file://localhost/var/folders/j2/78r9kp_d08gc52z04w2dwkv80000gn/T/ 
fileNames (
    "Heinrich Giesen 2.vcf" 
) 
resultPath /var/folders/j2/78r9kp_d08gc52z04w2dwkv80000gn/T/Heinrich Giesen 2.vcf 
vCard = 
BEGIN:VCAR 
VERSION:3.0 

。 。 。等々。

END:VCARD 
+0

ありがとう!明らかに私は* NSFilesPromisePboardType'をすべて登録しました。ドラッグが受信されているため、登録されているデータの種類に気づいていなかったので、登録されたデータの種類を確認しませんでした。私はそのタイプのために登録し、私のコードとあなたはうまくいった –

+0

実際に、私はちょうど私が私のデバッグコードを削除すると、それはうまく動作することを発見した。明らかに、各タイプのデータを出力すると、約束したファイルは無効になります。だから、デバッグのすべてが実際に値を取得することを妨げていました。 –

0

あなたがいますそのアドレスブックはペーストボードの動作を以前のOSバージョンからLionに変更しました。以前のvCardデータは、NSVCardPboardTypeタイプのペーストボードに直接格納されていました。しかし、ライオンでも、ドロップされたvCardを読むためのすべての情報を見つけることができます。

ペーストボードには2つの方法があります。 「直接」方法と「ダイアログ」方法。 (私の言葉ではなく、Appleのもの)。直接的には、すべてのデータがペーストボードに置かれます。ペーストボードでは、レシーバーがデータを見つけて読み取ることができます。時には、データが非常に頻繁に画像や長いテキスト(画像付きRTFD)のように大きくなると、時間と空間が非常に消費されることがあります。したがって、送信者と受信者の間に小さなダイアログが必要な別の方法が存在します。 (ドラッグ操作の)送信者は、(ほとんど)データをペーストボードに入れませんが、データをファイルシステムのどこかに格納することを約束します。レシーバー(ドラッグ操作の)は、この場所(フォルダー)がどこにあるべきかを伝えなければなりません。送信者からの回答は、新しく作成されたファイルの名前であり、受信者はこのファイルからデータを読み取ることができます。これはすべて-(BOOL)performDragOperation:(id <NSDraggingInfo>)senderの方法で行う必要があります。しかし、ドロップがtableView、outLineView、ブラウザなどで行われた場合は、別のメソッドを実装する必要があります。ドキュメントでacceptDrop:を検索してください。本質的に彼らはすべて同じです。あなたはペーストボード上のすべてのタイプのあなたのログに見ることができるように

- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation 
{ 
    NSPasteBoard *pb = [info draggingPasteboard]; 

    NSArray *types = pb.types; 

    if(([types containsObject: NSVCardPboardType]) && *data_exist for this type*){ 
     // read the data directly from here 
     . . . . 
     return YES; 
    } 

    if([types containsObject:NSFilesPromisePboardType]){ 
     // create a place for the promised data 
     NSString *destPath = NSTemporaryDirectory(); 
     NSURL *destURL = [NSURL fileURLWithPath:destPath isDirectory:YES]; 
     // let the sender know it 
     // the sender answers with filenames (without the path) 
     NSArray *fileNames = [sender namesOfPromisedFilesDroppedAtDestination:destURL]; 
     if(fileNames == nil) return NO; // Firefox likes to return nothing 
     NSString *resultStr = [destPath stringByAppendingPathComponent:[fileNames objectAtIndex:0]]; 
     // read the vCard data from here 
     . . . . . 
     return YES; 
    } 
    // search for other pbTypes or just return without success 
    return NO; 
} 

:あなたのケースでは

(のtableView以上低下)以下の(擬似)コードが(私はそう願って)仕事をしますNSFilesPromisePboardType(内部名はAppleファイルの約束台紙タイプ)は、単にデータがvcf(ファイルサフィックス)タイプであることを示す空でないpropertyListを持っています。このpbTypeを使うことは、AddressBookが動作する新しい方法です。これは、ファインダにデータを送信するのに好ましい方法です。

+0

まあ、用10.8+レジスタに

、私は以前、私はいくつかのより多くの掘削をしたので、約束したファイルをドラッグ働いていたが、それでもどこにも持ってませんでした。実際には 'com.apple.pasteboard.promised-file-content-type'(' NSFileContentsPboardType')のペーストボードタイプに焦点を当てる必要があると思います。しかし、それをどうやって使うのか分からないにもかかわらず、私はまだ役に立つ結果を得られません。すべてが無限になります。私は更新されたコードサンプルで私の質問を編集しようとします。 –

0

私もこの問題に取り組んでいます。読者のための要約。

NSFilesPromisePboardTypeおよびkUTTypeVCardの10.7レジスタにあります。 NSFilesPromisePboardTypeを処理します。あなたが意味を成して書いたものkUTTypeVCardとプロセスkUTTypeVCard

関連する問題