Titanium 5.2.0: iOS Live Photos

Titanium 5.2.0 has added support for Live Photos that Apple introduced with iOS 9.1 for the iPhone 6s. It allows you to select existing Live Photos and display them.

In this blog post I’ll walk you through all of this using the new Titanium 5.2.0 Sample App:

Capturing a Live Photo

Although Apple’s Reference isn’t really clear about it does say:

Live Photos is a Camera app feature on supported devices …

And that has indeed been our experience and that of app developers that work directly in Objective-C or Swift. Even when we do include the Live Photo media type, the UI for taking a new photo within another app will not include the Live icon and does not return a Live Photo. We will provide support soon after Apple does.

Selecting a Live Photo

To select a Live Photo from your device you use Ti.Media.openPhotoGallery() as always. Live Photos will always be selectable, but only if you include Ti.Media.MEDIA_TYPE_LIVEPHOTO in the mediaTypes will you get an actual livePhoto in the success response. Both ways, the existing media property will always get you the plain photo.

NOTE: You cannot use Ti.Media.MEDIA_TYPE_LIVEPHOTO without also including Ti.Media.MEDIA_TYPE_PHOTO in mediaTypes.

See the the Sample App’s livephoto.js controller for the implementation.

Displaying a Live Photo

Live Photos cannot be displayed in a Ti.UI.ImageView, but only the new Ti.UI.iOS.LivePhotoView.

Alloy does not yet support LivePhotoView which means we have to tell Alloy to use the Ti.UI.iOS namespace ourselves:

<LivePhotoView ns="Ti.UI.iOS" .. />

Set the view’s livePhoto property to the Ti.UI.iOS.LivePhoto proxy that you received from Ti.Media.openPhotoGallery().

The view supports force touch interaction with the Live Photo out of the box. Just force touch the view to play the Live Photo.

Programmatic Playback

You can also programmatically start and stop the playback. Use Ti.UI.iOS.LivePhotoView.startPlaybackWithStyle() to start and stopPlayback() to cancel. The first method accepts a parameter to select full playback or the hint style that you also see as a LivePhoto scrolls into view in the Photos app. This is also the only use case that Apple suggests you should use this method for.

In the livephoto.js controller we playback with hint style after we’ve initialised the LivePhotoView with the Live Photo you selected:



In addition to regular events, the view also features a start and stop event to inform you when the Live Photo has plays.