9
votes

I've been looking at adding iTunes Library access to a Mac app I'm developing.

I looked at some of the existing open source implementations, such as EyeTunes and iMedia - but found them to not be quite what I was looking for. Overkill in general.

So I tried out using the Scripting Bridge, and found that while functional it was slow. And since I didn't really need to control iTunes, the slowness was not worth it. It also had the downside of relying on iTunes to be running. It also is a bit irritating to get it working in a sandboxed app (though possible.)

So I finally started to roll my own by reading the iTunes Library.xml file. That seems to be working OK. But in the process of investigating the meaning of the Distinguished Kind key/value I stumbled upon a brand new, Apple supplied iTunesLibrary.framework !!!

Beautiful - the iTunesLibrary framework docs are here.

However, when I try to initialize the framework using the code as shown in the reference link:

NSError * error = nil;
ITLibrary* library = [ITLibrary libraryWithAPIVersion:@"1.0" error:&error];

It returns nil and provides the very helpful error like so (in my Sandboxed app):

Error Domain=NSPOSIXErrorDomain Code=100001 "Could not load." UserInfo=0x1140025b0 {NSLocalizedDescription=Could not load., NSUnderlyingError=0x1026fbe20 "The operation couldn’t be completed. (OSStatus error -50.)"}

Thinking it might be a sandboxing issue, I also created a quick command line utility that attempts to init the library and it returns an almost identical error:

Failed to open library: Error Domain=NSPOSIXErrorDomain Code=100001 "Could not load." UserInfo=0x1018015b0 {NSLocalizedDescription=Could not load., NSUnderlyingError=0x103a000e0 "The operation couldn’t be completed. (OSStatus error 100005.)"}

Has anyone else tried out this new iTunes Library framework with anymore luck than I have had?

// EDIT: Answer below is correct. Code signing is required. The sample code in the answer is a handy starting point for using the framework. Additionally, in my case the problem was also that the iTunesLibrary framework code does not appear to work when the iTunes library is hosted on a network drive. Make this a bit of a deal breaker unless Apple fixes it.

3
I am having the exact same error with the un-sandboxed code, but don't know how to fix it. I also had some trouble importing the Framework. I finally got it working by copy and pasting the framework into my project directory and adding that to the project. I'm wondering how it knows where to look for the iTunes Library.abroekhof
I was going to try this out to learn some objective-c but I can't even add it correctly to my project. Guessing the same issues as abroekhof... It adds to the project but I can´t import the header (not found). I have seen others using the scripting bridge. That may be the way to go? How did you add it to your project?Tobias Ritzau
abroekhof - You were able to get the library to initialize successfully in a code signed app by copying the Framework directly into your project?sckor
@sckor yes, is this bad? I actually just upgraded to Mountain Lion and now my app doesn't work anymore. What a drag. I'm getting the Could not load error as well.abroekhof
I did file a bug report with Apple. To which they almost immediately responded they could not reproduce. I provided them more details about my setup and haven't heard anything back since then. So I just went on with my original plan of accessing the iTunes Library.xml directly and forgetting about the new framework for now. Sorry to hear you're having trouble with the Framework now. :( I'd suggest filing a bug report so they know there are problems with the framework that still need to be worked on.sckor

3 Answers

7
votes

You'll need to codesign your app using a certificate from the Mac Developer Program.

It's not documented anywhere, but, my suspicion is that this requirement was added due to iTunes cloud being a web service thing that requires accessing user accounts.

// Edit: In addition to setting CODE_SIGN_IDENTITY in the project settings as discussed above, you will also need to add /Library/Frameworks to the FRAMEWORK_SEARCH_PATHS in the project settings so that Xcode will know where to look for the #import's.

// Edit 2: I wrote a quick little sample app to show how iTunesLibrary is used, since, Apple's sample code and documentation is rather sparse: https://github.com/zadr/iTunesLibraryExample

4
votes

From iTunes Library Framework Reference

  • You must code sign your app in order to get information back from the iTunes Library framework.
  • The iTunes Library framework is available to users running iTunes v11.0 or above.
1
votes

Not sure if this is true for all of you, but in my case, I kept Code-Signing-Identity to - helped me. Now I don't need to sign the app.