Product · November 28, 2018

Easily add Unsplash search into your iOS apps

Olivier Collet
Olivier Collet

Two months ago, we shared our first open source component for iOS. As I explained then, our strategy for open source on mobile is to offer native UI components that can be easily integrated, rather than a standard API wrapper.

UnsplashImageView was the appetizer, now comes the main dish with UnsplashPhotoPicker.

UnsplashPhotoPicker for iOS

This new component allows applications to easily search and download photos from the Unsplash library. With just a few lines of code, applications can offer beautiful, high-quality photos to their users, opening up entirely new mobile use cases.

Some examples:

  • Let’s say you’re a blogging platform that want to allow its users to insert photos from Unsplash into their blog posts, this component will make your life easy. (Medium 😉)
  • Or you could be a project management tool that offers its users to change the background for their projects. (Trello 😉)
  • Oh! You’re a service that helps people build their website, how about offering them to use high-quality photos from Unsplash on their homepage? (Squarespace 😉)
  • Or maybe you’re an app that specializes in making presentations, and want your users to insert beautiful photography to their amazing decks? We have you covered. (Apple 😉)

Before you can use it, you need to get Unsplash API access and secret keys. Visit our Unsplash API page to register as a developer for more information.

UnsplashPhotoPicker is a subclass of UIViewController and is configured very easily:

let configuration = UnsplashPhotoPickerConfiguration(
accessKey: ”<UNSPLASH_API_ACCESS_KEY>”,
secretKey: ”<UNSPLASH_API_SECRET_KEY>”
)
let photoPicker = UnsplashPhotoPicker(configuration: configuration)
photoPicker.photoPickerDelegate = self
present(photoPicker, animated: true, completion: nil)

To retrieve the selected photo, you implement the UnsplashPhotoPickerDelegate protocol:

func unsplashPhotoPicker(_ photoPicker: UnsplashPhotoPicker, didSelectPhotos photos: [UnsplashPhoto]) {
// Do something with the photos
}
view raw delegate.swift hosted with ❤ by GitHub

That’s it!

You can use a few more options to configure the photo picker. And take a look at UnsplashPhoto.swift to see the information that is returned.

You can find the project on Github: https://github.com/unsplash/unsplash-photopicker-ios


If you have any feedback or question, don’t hesitate to send an email at apps@unsplash.com.

And let us know if you use it in a project. Android equivalent coming soon.

Share article