Can I add a music library to the Xcode iOS Simulator?

一笑奈何 提交于 2019-11-30 11:44:20

Although the regular believe is that this can't be done I figured out how to do it thanks to the link @BaSha mentioned.

I wrote a little How To on it so everyone who faces the same problem or thinks it isn't possible will be able to get it working.

To give the gist of it you will need a few things.

  1. A iOS device that actually has music on it
  2. iFunBox or something similar
  3. The id of the simulator you want to use

To get the id of the device you want to test on you can run

xcrun simctl list

This will give you a list of all the available simulators, pick the one you want to use and copy the id, you will need this.

Now navigate to the directory of the simulator you just chose.

[yourHD] -> Users -> [yourusername] -> Library -> Developer -> CoreSimulator -> Devices -> [the ID you obtained in the previous step] -> data -> Media -> Itunes_Control -> Itunes

Now you have to open iFunBox (connect your phone with music library to your pc). In iFunBox, select Raw File System. In this you will find a directory called Itunes_Connect from that directory you need to copy some files and directories to the simulator directory you opened before. namely:

Music
iTunes/Artwork
iTunes/MediaLibrary.sqlitedb
iTunes/MediaLibrary.sqlitedb-shm
iTunes/MediaLibrary.sqlitedb-wal

If you ever bought music you should also grab the following directory Raw File System/Purchases

so I need to be able to see/add a music library to my simulator as well

You cannot do so. MPMediaLibrary APIs do not work on the simulator.

You can test your interface on the simulator by writing stub methods that stand between your code and the MPMediaLibrary APIs, but actual access to the user's music library is possible only on a device.

This is only possible with an actual device. You do not have any kind of music library on your simulator. You could develop another app with your music files and use it as a reference for testing but this seems too complicated and not very useful.

Actually you can add your device library to simulator. You will need:

  • An device with a music library on it
  • iFunBox
  • The id of the simulator you want to test this on

Run this command on terminal xcrun simctl list and will return a list that will tell you every id of every device. Take down the ID of the device you require.

Next we will actually navigate to the directory of this device:

[yourHD] -> Users -> [yourusername] -> Library -> Developer -> CoreSimulator -> Devices -> [the ID you obtained in the previous step] -> data -> Media -> Itunes_Control -> Itunes

Leave this directory open as you will need it in the next step.

Next up we will open the iFunBox application, you will need to connect your phone to your computer for this as iFunBox will allow is to look into the directories of your iPhone. When you’ve opened iFunBox you will need to select Raw File System. In here you will find the directory Itunes_Connect

From that directory on you will need to copy the following directories and files to the simulator directory you opened in the previous step

Music
iTunes/Artwork
iTunes/MediaLibrary.sqlitedb
iTunes/MediaLibrary.sqlitedb-shm
iTunes/MediaLibrary.sqlitedb-wal

If you ever bought music you should also grab the following directory Raw File System/Purchases

That’s it you should now be able to open your application and see the music files appear. You should even be able to play them!

Hope help you and somebody else with same question.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!