iOS 10 requestAuthorization

393 Views Asked by At

I don't know what's the wrong with this code, it always shows me this thing:fatal error: unexpectedly found nil while unwrapping an Optional value I got that thing when I try to get access to MPMediaLibrary, the code is this:

if (MPMediaLibrary.authorizationStatus() == MPMediaLibraryAuthorizationStatus.notDetermined) {

            // Access has not been determined.
            MPMediaLibrary.requestAuthorization({ (status: MPMediaLibraryAuthorizationStatus) in

                if (status == MPMediaLibraryAuthorizationStatus.authorized) {
                    let albumsQuery: MPMediaQuery = MPMediaQuery.albums()
                    let albumItems: [MPMediaItemCollection] = self.albumsQuery.collections! as [MPMediaItemCollection]
                }
            })
        }
0

There are 0 best solutions below