Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 3rd, 2012  |  syntax: None  |  size: 12.84 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Cannot drag vCard from Apple's Address Book to app in Mac OS X Lion
  2. - (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation
  3. {
  4.     NSPasteboard *pb = [info draggingPasteboard];
  5.  
  6.     NSArray *types = pb.types;
  7.     for (NSString *type in types)
  8.     {
  9.         NSLog(@" ");
  10.         NSLog(@"%@:", type);
  11.         NSLog(@"    property list = %@", [pb propertyListForType:type]);
  12.         NSLog(@"    data = %@", [pb dataForType:type]);
  13.         NSLog(@"    string = %@", [pb stringForType:type]);
  14.     }
  15.     NSLog(@" ");
  16.  
  17.     return YES;
  18. }
  19.        
  20. 2012-02-01 19:46:18.907 MyAppName[586:60b]  
  21. 2012-02-01 19:46:18.907 MyAppName[586:60b] dyn.ah62d4rv4gu8ycuwftb2gc5xeqzwfg3pqqzv1k4ptr3m1k6xmr3xyc6xwqf6zk8puqy:
  22. 2012-02-01 19:46:18.909 MyAppName[586:60b]     property list = (null)
  23. 2012-02-01 19:46:18.911 MyAppName[586:60b]     data = (null)
  24. 2012-02-01 19:46:18.912 MyAppName[586:60b]     string = (null)
  25. 2012-02-01 19:46:18.913 MyAppName[586:60b]  
  26. 2012-02-01 19:46:18.913 MyAppName[586:60b] ABExpandedSelectionStringArrayType:
  27. 2012-02-01 19:46:18.914 MyAppName[586:60b]     property list = (null)
  28. 2012-02-01 19:46:18.914 MyAppName[586:60b]     data = (null)
  29. 2012-02-01 19:46:18.915 MyAppName[586:60b]     string = (null)
  30. 2012-02-01 19:46:18.915 MyAppName[586:60b]  
  31. 2012-02-01 19:46:18.915 MyAppName[586:60b] dyn.ah62d4rv4gu8ycuwxqz0gn25yrf106y5ysmy0634bsm3gc8nytf2gn:
  32. 2012-02-01 19:46:18.917 MyAppName[586:60b]     property list = (null)
  33. 2012-02-01 19:46:18.918 MyAppName[586:60b]     data = (null)
  34. 2012-02-01 19:46:18.918 MyAppName[586:60b]     string = (null)
  35. 2012-02-01 19:46:18.918 MyAppName[586:60b]  
  36. 2012-02-01 19:46:18.919 MyAppName[586:60b] ABSelectionStringArrayType:
  37. 2012-02-01 19:46:18.919 MyAppName[586:60b]     property list = (null)
  38. 2012-02-01 19:46:18.921 MyAppName[586:60b]     data = (null)
  39. 2012-02-01 19:46:18.922 MyAppName[586:60b]     string = (null)
  40. 2012-02-01 19:46:18.922 MyAppName[586:60b]  
  41. 2012-02-01 19:46:18.922 MyAppName[586:60b] dyn.ah62d4rv4gu8yc6durvwwa3xmrvw1gkdusm1044pxqyuha2pxsvw0e55bsmwca7d3sbwu:
  42. 2012-02-01 19:46:18.922 MyAppName[586:60b]     property list = (
  43.     vcf
  44. )
  45. 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>
  46. 2012-02-01 19:46:18.923 MyAppName[586:60b]     string = <?xml version="1.0" encoding="UTF-8"?>
  47. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  48. <plist version="1.0">
  49. <array>
  50.     <string>vcf</string>
  51. </array>
  52. </plist>
  53. 2012-02-01 19:46:18.923 MyAppName[586:60b]  
  54. 2012-02-01 19:46:18.923 MyAppName[586:60b] Apple files promise pasteboard type:
  55. 2012-02-01 19:46:18.923 MyAppName[586:60b]     property list = (
  56.     vcf
  57. )
  58. 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>
  59. 2012-02-01 19:46:18.924 MyAppName[586:60b]     string = <?xml version="1.0" encoding="UTF-8"?>
  60. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  61. <plist version="1.0">
  62. <array>
  63.     <string>vcf</string>
  64. </array>
  65. </plist>
  66. 2012-02-01 19:46:18.924 MyAppName[586:60b]  
  67. 2012-02-01 19:46:18.925 MyAppName[586:60b] dyn.ah62d4rv4gu8ycuwuqz11a5dfnzeyk64uqm10c6xenv61a3k:
  68. 2012-02-01 19:46:18.925 MyAppName[586:60b]     property list = (
  69.     "C9786D5F-157A-4A65-A95E-C61752D2B4E3:ABPerson"
  70. )
  71. 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>
  72. 2012-02-01 19:46:18.926 MyAppName[586:60b]     string = <?xml version="1.0" encoding="UTF-8"?>
  73. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  74. <plist version="1.0">
  75. <array>
  76.     <string>C9786D5F-157A-4A65-A95E-C61752D2B4E3:ABPerson</string>
  77. </array>
  78. </plist>
  79. 2012-02-01 19:46:18.926 MyAppName[586:60b]  
  80. 2012-02-01 19:46:18.926 MyAppName[586:60b] ABPeopleUIDsPboardType:
  81. 2012-02-01 19:46:18.927 MyAppName[586:60b]     property list = (
  82.     "C9786D5F-157A-4A65-A95E-C61752D2B4E3:ABPerson"
  83. )
  84. 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>
  85. 2012-02-01 19:46:18.937 MyAppName[586:60b]     string = <?xml version="1.0" encoding="UTF-8"?>
  86. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  87. <plist version="1.0">
  88. <array>
  89.     <string>C9786D5F-157A-4A65-A95E-C61752D2B4E3:ABPerson</string>
  90. </array>
  91. </plist>
  92. 2012-02-01 19:46:18.937 MyAppName[586:60b]  
  93. 2012-02-01 19:46:18.937 MyAppName[586:60b] public.vcard:
  94. 2012-02-01 19:46:18.942 MyAppName[586:60b]     property list = (null)
  95. 2012-02-01 19:46:18.944 MyAppName[586:60b]     data = (null)
  96. 2012-02-01 19:46:18.945 MyAppName[586:60b]     string = (null)
  97. 2012-02-01 19:46:18.945 MyAppName[586:60b]  
  98. 2012-02-01 19:46:18.945 MyAppName[586:60b] Apple VCard pasteboard type:
  99. 2012-02-01 19:46:18.945 MyAppName[586:60b]     property list = (null)
  100. 2012-02-01 19:46:18.946 MyAppName[586:60b]     data = (null)
  101. 2012-02-01 19:46:18.946 MyAppName[586:60b]     string = (null)
  102. 2012-02-01 19:46:18.948 MyAppName[586:60b]  
  103. 2012-02-01 19:46:18.949 MyAppName[586:60b] dyn.ah62d4rv4gu8z82xqqz1gk3penm11swpsqvw1u3px:
  104. 2012-02-01 19:46:18.949 MyAppName[586:60b]     property list = (null)
  105. 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>
  106. 2012-02-01 19:46:18.949 MyAppName[586:60b]     string = (null)
  107. 2012-02-01 19:46:18.949 MyAppName[586:60b]  
  108. 2012-02-01 19:46:18.950 MyAppName[586:60b] _blendedRowIndexes:
  109. 2012-02-01 19:46:18.950 MyAppName[586:60b]     property list = (null)
  110. 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>
  111. 2012-02-01 19:46:18.950 MyAppName[586:60b]     string = (null)
  112. 2012-02-01 19:46:18.950 MyAppName[586:60b]  
  113. 2012-02-01 19:46:18.950 MyAppName[586:60b] com.apple.pasteboard.promised-file-content-type:
  114. 2012-02-01 19:46:18.951 MyAppName[586:60b]     property list = public.vcard
  115. 2012-02-01 19:46:18.951 MyAppName[586:60b]     data = <7075626c 69632e76 63617264>
  116. 2012-02-01 19:46:18.951 MyAppName[586:60b]     string = public.vcard
  117. 2012-02-01 19:46:18.952 MyAppName[586:60b]  
  118. 2012-02-01 19:46:18.952 MyAppName[586:60b] com.apple.pasteboard.promised-file-url:
  119. 2012-02-01 19:46:18.954 MyAppName[586:60b]     property list = (null)
  120. 2012-02-01 19:46:18.954 MyAppName[586:60b]     data = <>
  121. 2012-02-01 19:46:18.954 MyAppName[586:60b]     string =
  122. 2012-02-01 19:46:18.955 MyAppName[586:60b]  
  123. 2012-02-01 19:46:18.955 MyAppName[586:60b] dyn.ah62d4rv4gu8y6y4usm1044pxqzb085xyqz1hk64uqm10c6xenv61a3k:
  124. 2012-02-01 19:46:18.955 MyAppName[586:60b]     property list = (null)
  125. 2012-02-01 19:46:18.956 MyAppName[586:60b]     data = <>
  126. 2012-02-01 19:46:18.956 MyAppName[586:60b]     string =
  127. 2012-02-01 19:46:18.956 MyAppName[586:60b]  
  128. 2012-02-01 19:46:18.956 MyAppName[586:60b] NSPromiseContentsPboardType:
  129. 2012-02-01 19:46:18.956 MyAppName[586:60b]     property list = (null)
  130. 2012-02-01 19:46:18.957 MyAppName[586:60b]     data = <>
  131. 2012-02-01 19:46:18.957 MyAppName[586:60b]     string =
  132. 2012-02-01 19:46:18.957 MyAppName[586:60b]
  133.        
  134. - (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation
  135. {
  136.     NSPasteboard *pb = [info draggingPasteboard];
  137.  
  138.     // Supposed to call this before readFileContentsType:toFile: for some reason
  139.     NSArray *types = pb.types;
  140.  
  141.     NSString *destPath = NSTemporaryDirectory();
  142.     NSURL *destURL = [NSURL fileURLWithPath:destPath isDirectory:YES];
  143.     NSArray *fileNames = [info namesOfPromisedFilesDroppedAtDestination:destURL];
  144.     NSLog(@"fileNames = %@", fileNames);
  145.  
  146.     NSString *afile = [pb readFileContentsType:nil toFile:@"random_filename"];
  147.     // Tried with (NSString *)kUTTypeVCard as well, same results
  148.     NSLog(@"afile = %@", afile);
  149.     // What do I do with this result?
  150.     NSString *card = [NSString stringWithContentsOfFile:afile];
  151.     NSLog(@"card = %@", card);
  152.  
  153.     NSFileWrapper *wrapper = [pb readFileWrapper];
  154.     NSLog(@"wrapper = %@", wrapper);
  155.  
  156.     return YES;
  157. }
  158.        
  159. 2012-02-05 12:36:58.419 MyAppName[3650:60b] fileNames = (null)
  160. 2012-02-05 12:36:58.419 MyAppName[3650:60b] afile = random_filename
  161. 2012-02-05 12:36:58.419 MyAppName[3650:60b] card = (null)
  162. 2012-02-05 12:36:58.420 MyAppName[3650:60b] wrapper = (null)
  163.        
  164. - (BOOL)  tableView:(NSTableView *)aTableView
  165.          acceptDrop:(id <NSDraggingInfo>)info
  166.                 row:(NSInteger)row
  167.       dropOperation:(NSTableViewDropOperation)operation
  168. {
  169.     NSPasteboard *pboard = [info draggingPasteboard];
  170.     NSArray *types = pboard.types;
  171.  
  172.     if( [types containsObject:NSFilesPromisePboardType] ){
  173.         NSString *destPath = NSTemporaryDirectory();  // or whatever you want
  174.         NSURL *destURL = [NSURL fileURLWithPath:destPath isDirectory:YES];
  175.         NSLog(@"destURL %@", destURL);
  176.         NSArray *fileNames = [info namesOfPromisedFilesDroppedAtDestination:destURL];
  177.         NSLog(@"fileNames %@", fileNames);
  178.         if( fileNames == nil ) return NO;
  179.         NSString *resultPath = [destPath stringByAppendingPathComponent:[fileNames objectAtIndex:0]];
  180.         NSLog(@"resultPath %@", resultPath);
  181.         // read the vCard data from here
  182.         NSString *vCard = [NSString stringWithContentsOfFile:resultPath
  183.                                                     encoding:NSASCIIStringEncoding
  184.                                                        error:NULL];
  185.         NSLog(@"vCard =n%@", vCard);
  186.         return YES;
  187.     }
  188.     return NO;
  189. }
  190.        
  191. destURL file://localhost/var/folders/j2/78r9kp_d08gc52z04w2dwkv80000gn/T/
  192. fileNames (
  193.     "Heinrich Giesen 2.vcf"
  194. )
  195. resultPath /var/folders/j2/78r9kp_d08gc52z04w2dwkv80000gn/T/Heinrich Giesen 2.vcf
  196. vCard =
  197. BEGIN:VCAR
  198. VERSION:3.0
  199.        
  200. END:VCARD
  201.        
  202. - (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id < NSDraggingInfo >)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation
  203. {
  204.     NSPasteBoard *pb = [info draggingPasteboard];
  205.  
  206.     NSArray *types = pb.types;
  207.  
  208.     if( ([types containsObject: NSVCardPboardType]) && *data_exist for this type* ){
  209.        // read the data directly from here
  210.        . . . .
  211.        return YES;
  212.     }
  213.  
  214.     if( [types containsObject:NSFilesPromisePboardType] ){
  215.       // create a place for the promised data
  216.       NSString *destPath = NSTemporaryDirectory();
  217.       NSURL *destURL = [NSURL fileURLWithPath:destPath isDirectory:YES];
  218.       // let the sender know it
  219.       // the sender answers with filenames (without the path)
  220.       NSArray *fileNames = [sender namesOfPromisedFilesDroppedAtDestination:destURL];
  221.       if( fileNames == nil ) return NO;  // Firefox likes to return nothing
  222.       NSString *resultStr = [destPath stringByAppendingPathComponent:[fileNames objectAtIndex:0]];
  223.       // read the vCard data from here
  224.          . . . . .
  225.       return YES;
  226.     }
  227.     // search for other pbTypes or just return  without success
  228.     return NO;
  229. }