Posted on by & filed under Content - Highlights and Reviews, Programming & Development.

A guest post by Engin Kurutepe, an iOS team lead at Txtr, where he is responsible for e-reader apps on iOS devices. Previously, Engin developed the Moped iOS app and was involved with various other iOS projects and startups, including the best selling e-book app in Turkey. He can be best reached via twitter: @ekurutepe

One of the most interesting new features of iOS 7 is the AirDrop functionality. AirDrop allows users to send files between devices without the need for an Internet connection by establishing a direct connection between two devices using the built-in Bluetooth and WiFi protocols. This makes it very easy and very fast to exchange data between devices and can be a valuable competitive advantage for the apps that need to transfer files between iOS devices.

While sending files over AirDrop is quite easy, receiving them is a bit more involved, but nothing to be afraid of. Let’s look at some example code to see how AirDrop support can be added to your app.

Sending files

To enable your own app to have the option to share files over AirDrop, you need use the system provided class UIActivityViewController:

Where _url is the file URL of the file that you would like to send. After initialization, the activities controller is modally presented. If there are any other devices with AirDrop turned on nearby, the activity controller will automatically show them and handle the file transfer for you.

That’s it! No, really, you don’t need to do more to send files over AirDrop from your app!

Receiving Files

In order to be able to receive files over AirDrop there are two steps that you need to implement:

  • Declare your app as a handler for the desired files types
  • Handle the received AirDrop file in your app delegate

If you want your app to be recognized as a handler for a certain file type, you have to declare it as such by adding the corresponding UTI in your Info.plist. In Xcode 5 this can be achieved by going to the Info tab under your build target and adding the desired UTI under “Document Types.” One important caveat here is that some UTIs are reserved for the system. For instance, if you declare your app as a handler for public.image, public.jpeg or public.png, this will not be honored by the system at run time because those UTIs seem to be reserved for Apple’s own Camera and Photo apps.

After you have declared your desired UTIs, you need to implement the application:openURL:sourceApplication:annotation: method in your application delegate. When the system routes an AirDrop file to your app, this method will get called and the URL will point to a file in your app’s /Documents/Inbox directory. This directory is a special directory where your app has only read permissions. If you need to modify the file, you must move it to another directory first. Another point to pay attention to is how the files in this directory can be encrypted using data protection. In a normal case, the files inside your apps documents directory are freely available, but in some cases, by the time this method gets called, the user could have already locked the device. Therefore, it is a good idea to check if the file is readable first by using the protectedDataAvailable property of the application object that gets passed to this delegate method as the first parameter. Apple documentation recommends to save the AirDrop URL for later and to return YES from this method, even if the file could not be accessed due to data protection.


If you would like to get up to speed on further new technologies introduced in iOS 7 such as UIKit Dynamics, Multipeer Connectivity, Custom View Controller Transitions and much more, check out our book Developing an iOS 7 Edge, which I wrote with an amazing group of top-notch iOS developers.

Be sure to look at the iOS 7 resources that you can find in Safari Books Online.

Not a subscriber? Sign up for a free trial.

Safari Books Online has the content you need

Developing an iOS 7 Edge was written by six iOS developers with expertise in the various aspects of iOS 7. The result of this collaboration is a dense ebook focused solely on iOS 7 development (it doesn’t start with iOS 6 info and add on) and backed by the authors’ real-world experience, as well as a working BepBop app that demonstrates how all of the examples work in practice. The introduction of iOS 7 lays the foundation for developing new classes of application, and we hope to show you the way.
iOS 7 Programming Cookbook will help you overcome the vexing issues you’ll inevitably confront when creating apps for the iPhone, iPad, or iPod touch. By making use of new and thoroughly revised recipes in this updated cookbook, you’ll quickly learn the steps necessary to write complete iOS apps using the iOS 7 SDK—including ways to store and protect data, send and receive notifications, enhance and animate graphics, manage files and folders, and take advantage of UI Dynamics.
In iOS 7 Programming Fundamentals, the author backs up the conversation to the C programming language and objective programming so that the reader can really understand why and how objective-c does its job. Next in line is Xcode, which is significantly updated in its 5th version. The author talks about the interface, documentation, and lifecycle of a project. Finally, the book closes out with a look at Cocoa, Apple’s framework for creating apps. The reader will come to understand how the idiosyncrasies of the framework allows for clean, optimized programs.
Programming iOS 7, 4th Edition will help you get a solid grounding in all the fundamentals of Cocoa Touch, and avoid problems during iPhone and iPad app development. With this revised edition, you’ll dig into Cocoa and learn how to work effectively with Objective-C and Xcode. This book covers iOS 7 in a rigorous, orderly fashion—ideal whether you’re approaching iOS for the first time or need a reference to bolster existing skills.

About the author

engin-mugshot Engin Kurutepe, co-author of Developing an iOS 7 Edge, is an iOS team lead at Txtr, where he is responsible for e-reader apps on iOS devices. Previously, Engin developed the Moped iOS app and was involved with various other iOS projects and startups, including the best selling e-book app in Turkey. In his spare time, he is developing GeoTagBee, an iPhone app which makes it easy to add geolocation information to photos from any digital camera. He used to conduct research and publish papers on the compression and streaming of multi-camera 3D video in a previous life, before he dropped out of his PhD and started working on iOS full-time. He is originally from Istanbul, Turkey and has been calling Berlin, Germany home since 2006. He can be best reached via twitter: @ekurutepe .

Tags: AirDrop, Bluetooth, iOS 7,, Multipeer Connectivity, Transitions, UIKit Dynamics, UTI, Wifi,

Comments are closed.