I am developing a music app where i need to copy songs from iPhone music library to my app's document directory. I need the Objective-C code or framework if any to select multiple songs from music app and save to my app. I have search stackoverflow but could not find a complete solution.
-
5Welcome to SO, please be a bit more specific when asking question: what have you tried, what do you expect, etc. See [how to ask](http://stackoverflow.com/help/how-to-ask) – Nehal Jan 27 '16 at 05:18
-
Thank u. I have tried this. https://bitbucket.org/artgillespie/tslibraryimport – kathrineshineshine Jan 27 '16 at 05:23
-
I want that songs be imported with all its meta data – kathrineshineshine Jan 27 '16 at 05:23
4 Answers
Please refer below Links..
You can access the Media Files in iTunes using MPMediaPickerController
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];
mediaPicker.delegate = self;
mediaPicker.allowsPickingMultipleItems = YES; // this is the default
[self presentModalViewController:mediaPicker animated:YES];
Below link is what you need.
http://iphoneghostrider.blogspot.in/2014/05/import-music-and-save-it-to-document.html
Below link is used to Import Media Files to Documents Directory
Application crashed while importing songs from Ipod library in Iphone for iOs 5.0
Below link is the sample give by Apple
https://developer.apple.com/library/ios/samplecode/AddMusic/Introduction/Intro.html
Hope it helps you...!

- 1
- 1

- 5,369
- 4
- 26
- 59
Swift 4 version based on Vidhyanand's answer:
let pickerController = MPMediaPickerController(mediaTypes: .music)
pickerController.delegate = self
present(pickerController, animated: true)
Also make sure to include the following usage description to your Info.plist
, otherwise the picker will not be presented:
<key>NSAppleMusicUsageDescription</key>
<string>Usage description</string>

- 392
- 1
- 5
- 12
You need the Media Player framework:
MPMediaLibrary, MPMediaQuery, etc.
MPMediaQuery *everything = [[MPMediaQuery alloc] init];
NSLog(@"Logging items from a generic query...");
NSArray *itemsFromGenericQuery = [everything items];
for (MPMediaItem *song in itemsFromGenericQuery) {
NSString *songTitle = [song valueForProperty: MPMediaItemPropertyTitle];
NSLog (@"%@", songTitle);
}
(OR)
Try this link
http://code.tutsplus.com/tutorials/ios-sdk-music-library-access--mobile-6188

- 283
- 5
- 28
-
sir i want the songs to be imported and saved in my apps document folder. Also i want that songs be imported with all their meta data – kathrineshineshine Jan 27 '16 at 05:21
-
follow this link......step by step http://code.tutsplus.com/tutorials/ios-sdk-music-library-access--mobile-6188 – Sudheer Kolasani Jan 27 '16 at 05:30
Open Xcode and select “Create a new Xcode project”. Select “view-based application” and click “next”. Enter a name for your project (I called mine “Music”), enter your company identifier, make sure you select iPhone for device family, and then click “next”. Choose a place to save your project and click “create”.
Step 2: Import the MediaPlayer Framework In the navigator area of Xcode 4, select the project name (in our case “Music”). Next, select the current target (“Music” here again), and then select the “Build Phases” tab. Expand the “Link Binary With Libraries” option, and then click the “+” button to add a new framework. Type “MediaPlayer″ into the search box, and select the MediaPlayer.framework option that appears in the list. Click “Add” to include this framework in the linking phase of your project.Now that you have added the media player framework into your project, you need to import that framework into the view controller that will use the iPod library. Go to the MusicViewController.h file and insert the following line of code below the UIKit Step 3: Importing the Project Images Download the source code and drag the images map to your project. Make sure that the checkbox by Copy item into destination group’s folder (if needed) is checked. This map contains the images we will use in this app.
Step 4: Designing the Interface In the “Music” folder in the “Project Navigator” click on MusicViewController.xib.
Drag a UIImageView from the library to the view. Make sure the utilities window is shown and go to the Size Inspector. Set both the width and height to 200, the x-coordinate to 60 and the y-coordinate to 20. This image view will show the songs artwork.
Now drag a UISlider to the view and arrange it with the blue guide lines to the bottom of the view. Also make it a bit wider, so it uses the entire width of the view between the two blue guidelines. We will use this slider to adjust the volume.
Now drag 4 UIButtons to the view. Drag the first one under the image view and set its title to “Show Media Picker”. This one will do just what the text says. The other three buttons will be the control buttons. Select the other three buttons and go to the Attributes Inspector. Set the type to Custom and set the image of the buttons respectively to PreviousButton.png, PlayButton.png and NextButton.png. Arrange the buttons like below.
At last, drag three UILabels to the view. Delete the text of all the labels and arrange them like below (I added some text, so you can see where the labels are. You won’t need to add this text). These labels will show some information about the currently playing song.
Step 5: Making the IB Connections Now that we have designed out interface, we can make the connections. Click the middle button of the editor to show the assistant editor .
Click the image view and CTRL-drag to the interface. A pop-up will show. Enter the text “artworkImageView” for name and then click “connect.”
Now Click the slider and connect it the same way, but name it “volumeSlider”. CTRL-drag again from the slider to the interface, but this time under the curly braces. Set the connection to Action instead of Outlet. Enter “volumeChanged” for the name and make sure the event is Value Changed and click “connect”.
These 4 buttons also need actions. Connect them the same way the slider action was connected. Name the actions as follows:
Show Media Picker button: showMediaPicker Previous button: previousSong Play button: playPause Next button: nextSong The play button also needs an outlet. Connect it the same way we connected the outlet for the image view, but name it “playPauseButton”.
At last we need to create the outlets for the labels. Connect them again the same way we connected the image view outlet. Name the first label “titleLabel”, the second label “artistLabel” and the last label “albumLabel”.