An object that represents the state of synced media items on a device.


class MPMediaLibrary : NSObject


A user may sync their device, changing the contents on the device, while your app is running. You can use the notification provided by this class to ensure that your app's cache of the user's library is up-to-date.

To retrieve media items from the media library, build a custom query as described in MPMediaPropertyPredicate and MPMediaQuery.


Getting the Default Media Library

class func requestAuthorization((MPMediaLibraryAuthorizationStatus) -> Void)

Displays a user interface so that the user can authorize whether your app may view the media library's contents.

class func authorizationStatus() -> MPMediaLibraryAuthorizationStatus

Returns whether the app can access the user's media library.

enum MPMediaLibraryAuthorizationStatus

The list of possible states for authorization to access to the user's media library.

class func `default`() -> MPMediaLibrary

Returns an instance of the default media library.

Receiving Notifications when the User's Library Changes

func beginGeneratingLibraryChangeNotifications()

Asks the media library to turn on notifications for whenever the library changes.

func endGeneratingLibraryChangeNotifications()

Asks the media library to turn off notifications for whenever the library changes.

static let MPMediaLibraryDidChange: NSNotification.Name

Indicates the media library has changed.

var lastModifiedDate: Date

The calendar date on which the media library was last modified.

Retrieving a Playlist from the Media Library

func getPlaylist(with: UUID, creationMetadata: MPMediaPlaylistCreationMetadata?, completionHandler: (MPMediaPlaylist?, Error?) -> Void)

Retrieves an app maintained existing playlist or creates a new playlist when no playlist exists.

Adding an Item to the Media Library


Inherits From