简体   繁体   English

使用新的iTunesLibrary Framework访问Mac OS-X上的iTunes库

[英]Using new iTunesLibrary Framework to access iTunes library on Mac OS-X

I've been looking at adding iTunes Library access to a Mac app I'm developing. 我一直在寻找添加iTunes库访问我正在开发的Mac应用程序。

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. 我查看了一些现有的开源实现,例如EyeTunesiMedia - 但发现它们并不是我想要的。 Overkill in general. 矫枉过正。

So I tried out using the Scripting Bridge , and found that while functional it was slow. 所以我尝试使用Scripting Bridge ,发现虽然功能很慢。 And since I didn't really need to control iTunes, the slowness was not worth it. 由于我并不真的需要控制iTunes,因此速度缓慢并不值得。 It also had the downside of relying on iTunes to be running. 它也有依赖iTunes运行的缺点。 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. 所以我终于通过阅读iTunes Library.xml文件开始自己动手了。 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 !!! 但是在调查Distinguished Kind键/值的意义的过程中,我偶然发现了一个全新的,Apple提供了iTunesLibrary.framework !!!

Beautiful - the iTunesLibrary framework docs are here. 美丽 - iTunesLibrary框架文档在这里。

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): 它返回nil并提供非常有用的错误(在我的Sandboxed应用程序中):

Error Domain=NSPOSIXErrorDomain Code=100001 "Could not load." 错误域= NSPOSIXErrorDomain代码= 100001“无法加载”。 UserInfo=0x1140025b0 {NSLocalizedDescription=Could not load., NSUnderlyingError=0x1026fbe20 "The operation couldn't be completed. (OSStatus error -50.)"} UserInfo = 0x1140025b0 {NSLocalizedDescription =无法加载。,NSUnderlyingError = 0x1026fbe20“操作无法完成。(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." 无法打开库:错误域= NSPOSIXErrorDomain代码= 100001“无法加载”。 UserInfo=0x1018015b0 {NSLocalizedDescription=Could not load., NSUnderlyingError=0x103a000e0 "The operation couldn't be completed. (OSStatus error 100005.)"} UserInfo = 0x1018015b0 {NSLocalizedDescription =无法加载。,NSUnderlyingError = 0x103a000e0“操作无法完成。(OSStatus错误100005。)”}

Has anyone else tried out this new iTunes Library framework with anymore luck than I have had? 有没有其他人尝试过这个新的iTunes图书馆框架,而不是我的运气?

// 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. 此外,在我的情况下,问题还在于当iTunes库托管在网络驱动器上时,iTunesLibrary框架代码似乎不起作用。 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. 您需要使用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. 它没有记录在任何地方,但是,我怀疑是由于iTunes云是一个需要访问用户帐户的Web服务的东西而增加了这个要求。

// 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. // 编辑 :除了CODE_SIGN_IDENTITY在项目设置中设置CODE_SIGN_IDENTITY之外,您还需要在项目设置中将/Library/Frameworks添加到FRAMEWORK_SEARCH_PATHS ,以便Xcode知道在哪里查找CODE_SIGN_IDENTITY

// 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 // 编辑2 :我写了一个快速的小样本应用程序,以显示如何使用iTunesLibrary,因为Apple的示例代码和文档相当稀疏: https//github.com/zadr/iTunesLibraryExample

From iTunes Library Framework Reference 来自iTunes Library Framework Reference

  • You must code sign your app in order to get information back from the iTunes Library framework. 您必须对应用程序进行代码签名,以便从iTunes资料库框架中获取信息。
  • The iTunes Library framework is available to users running iTunes v11.0 or above. iTunes Library框架适用于运行iTunes v11.0或更高版本的用户。

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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM