You cannot successfully test this code on an xCode simulator. You need to use a real device (iPhone/iPad).
That being said, you could make sure that you have the correct settings in your info.plist:
Privacy - Media Library Usage Description -> set string value describing what needs authorization.
Topic:
Media Technologies
SubTopic:
General
Tags: