سؤال

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.

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

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.

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top