Receiving Files through AirDrop using Xamarin.iOS

Receiving Files

In order to receive files from AirDrop, two steps must be taken.

  1. Register your application as a handler for a specific file type.
  2. Actually handle the AirDrop action.

The first item can be done by adding the correct UTI in info.plist file. It’s worth noting that there are some system level UTIs, such as images (public.jpeg, public.png), that cannot be used/handled within an app. Below is an example for handling PDF files.

<key>CFBundleVersion</key>
<string></string>
<key>CFBundleTypeName</key>
<string>PDF</string>
<key>LSHandlerRank</key>
<string>Default</string>
<key>LSItemContentTypes</key>
<array>
<string>com.adobe.pdf</string>
</array>

Item 2 is taken care of by overriding the OpenUrl method in the AppDelegate. AirDrop places the file in your applications /Documents/Inbox . This directory is read-only, so if the file needs to be modified it must be copied off somewhere.

        public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
        {
            new UIAlertView("Airdrod File Received!", "File " + url + " received!", null, "OK", null).Show();
            return true;
        }

I have update the sample on GitHub to include these changes.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s