Drag and Drop files to Juce component (iOS, AUv3)

Here is my working solution for Drag & Drop files for iOS. This is pretty much first Juce+Obj-C wrapper I made from scratch, so I would be happy to hear any comments if its ok in terms of ARC and thread safety.

Few details that might be useful:

  • The integration is pretty straightforward. Just attach the singleton to the peer using FileDropContainer::getInstance()->setParentComponent(getTopLevelComponent()); in your editor ctor and that’s all: regular Juce::FileDragAndDropTarget methods should be called from now on.
  • Until the object is dropped we don’t have access to the full file name, thus we can’t read extension, so the decision about accepting particular file type is made on the wrapper level via native method canHandleSession. All methods of Juce::FileDragAndDropTarget except filesDropped will get just file names without extensions.
  • StringArray passed to filesDropped method contains native iOS bookmarks converted to juce::String (with special prefix). Bookmarks recieved can be converted to juce::URL in order to access file and store the bookmark for later use. I have a separate juce::URL wrapper to handle bookmarks. More info on bookmarks can be found here and here. I can share my solution as well
  • This implementation accepts audio files. However, I couldn’t make it accept objects from Voice Memos yet. Perhaps, this is what @luzifer mentioned about accepting dynamically created objects, but for now no idea what native iOS class with audio data is passed.
  • In order to include MP3, FLAC and OGG to kUTTypeAudio (public.audio) I had to register them in PList:
<plist>
  <dict>
    <key>UTImportedTypeDeclarations</key>
    	<array>
      		 <dict>
			          <key>UTTypeIdentifier</key>
          			<string>org.xiph.flac</string>
			          <key>UTTypeDescription</key>
			          <string>FLAC Audio</string>
			          <key>UTTypeConformsTo</key>
			          <array>
				            <string>public.audio</string>
			          </array>
			          <key>UTTypeTagSpecification</key>
			          <dict>
				            <key>public.filename-extension</key>
				            <array>
					              <string>flac</string>
            				</array>
         			</dict>
		       </dict>
      		 <dict>
			          <key>UTTypeIdentifier</key>
          			<string>public.mp3</string>
			          <key>UTTypeDescription</key>
			          <string>MP3 Audio</string>
			          <key>UTTypeConformsTo</key>
			          <array>
				            <string>public.audio</string>
			          </array>
			          <key>UTTypeTagSpecification</key>
			          <dict>
				            <key>public.filename-extension</key>
				            <array>
					              <string>mp3</string>
            				</array>
         			</dict>
		       </dict>
       <dict>
			          <key>UTTypeIdentifier</key>
          			<string>org.xiph.ogg</string>
			          <key>UTTypeDescription</key>
			          <string>OGG Vorbis Audio</string>
			          <key>UTTypeConformsTo</key>
			          <array>
				            <string>public.audio</string>
			          </array>
			          <key>UTTypeTagSpecification</key>
			          <dict>
				            <key>public.filename-extension</key>
				            <array>
					              <string>ogg</string>
            				</array>
         			</dict>
		       </dict>
	    </array>
  </dict>
</plist>
3 Likes