Using new iTunesLibrary Framework to access iTunes library on Mac OS-X - objective-c

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.

Related

Invalid Binary Or Invalid Swift Support

After I send my app for approval to the app store I get the message 'Invalid Binary' in the iTunes Connect. Then I get the following message in an email from Apple:
Invalid Swift Support - The bundle contains an invalid implementation of Swift. The app may have been built or signed with non-compliant or pre-release tools. Visit developer.apple.com for more information.
My app is just a simple game application. No external programs are called. I have researched this message and went through and checked the following:
xcode is up to date - checked in app store
EMBEDDED_CONTENT_CONTAINS_SWIFT to YES or NO
send with the xcode app, not the application loader
did NOT build with the command line
(Xcode menu -> Preferences -> Locations tab - verified that the Command Line Tools matches Xcode version.
"Clean"ed the app, rebuilt and rearchived and then resent, same message
The app validates through the organizer fine
viewing the contents of the archive shows a SwiftSupport folder
I am only using one developer account and have never logged into any other developer account
I cannot find anything online that would help solve this problem.
I am running OS X Yosemite 10.10.1.
xcode version is 6.1.1 version 6A2008a - built, cleaned and sent with this version
I have also pressed the Option key and "Cleaned Build Folder" and resent, same message
I cannot find any other reason for this online or in any forums. Any help is greatly appreciated. Thank you for your time.
SOLUTION I FIND
Edit:
(1)
One you contact Apple and you wait long time … for reset iTunes connect because this problem coming in Apple . (Apple ask to send log of this problem)
(2)
An other solution, your create an other project application on iTunes connect and upload your work, this solution work fine, is the solution for me .
(3)
An other solution, you create a new project on Xcode, copy and paste your project in this other project.... (create new provisioning profile etc..) And upload your work in the same project application on Itunes Connect.
(4)
Step (2) + step (3), create a new project in Xcode and Itunes Connect.
(5)
Create a new project with the same name bundle identifier, it works perfectly !
See: Technical Q&A QA1881 Embedding Content with Swift in Objective-C.
It seems that you only need to set EMBEDDED_CONTENT_CONTAINS_SWIFT to YES "If you are building an app that does not use Swift but embeds content such as a framework that does".
What language is your app written in? If Swift yo do not need EMBEDDED_CONTENT_CONTAINS_SWIFT.
I ran into this problem the other day. Took some doing, but I finally figured out the problem ( for me at least). Everything I read online said the problem had to do with this setting:
EMBEDDED_CONTENT_CONTAINS_SWIFT
When this started failing, I had this set to NO. So I tried setting it to YES, and it still failed for the same reason. The GUI wouldn't let me remove this setting, I could only change it between YES and NO.
For what it's worth, my code has no EMBEDDED code, it's all just straight up SWIFT.
Anyway, so I decided to uninstall XCode and redownload it, hoping that would help.
While XCode was downloading, I fired up Beyond Compare, and compared my current project, with a backup from last week, to see what could have changed.
Beyond Compare found that a file deep inside the Projectname.xcodeproj file, changed ... a file called project.pbxproj file.
Inside this, was that line:
EMBEDDED_CONTENT_CONTAINS_SWIFT = NO;
This appeared in the current version of my project (that was failing). Interestingly enough, this line didn't exist at ALL in the old backup version from a week ago. I know that I didn't set this flag. There must have been something in Xcode that did it under the covers.
Anyway with that knowledge, Xcode finished downloading, and I reinstalled. Started it up, opened my project, and magically, Xcode REMOVED that line from the .pbxproj file, and now my project uploaded to itunesConnect sucessfully.
BottomLine: There's a bug in xcode that it may decide to add this line to your project for no reason, making your project invalid.
Solution: Editing the pbxproj file yourself and removing that line might work ... but reinstalling XCode seemed to clear up any confusion it had, and it removed it for me.
If you are submitting an app that has an AppleWatch extension, you can get this error if you try and submit the app using the Application Loader utility and a zip file. I got the error:
The bundle contains an invalid implementation of Swift. and
The bundle contains an invalid implementation of WatchKit.
I went through pretty much every solution for the first of the errors - but it was submitting via Xcode that fixed it.
well xcode 6.1 is a bit old and contains old swift. xcode 6.4 is the newest public one IIRC
"Check your code signing. I had this error when in automatic signing. I Put my dev profile for dev and production profile for release version and error is gone."
Link for the Quote
Sometimes this happens inadvertently.
To be safe, all components of your app should be built with the same version of Xcode and the Swift compiler to ensure that they work together.
I think you need to do a pod clean and install. I reckon one of your swift pods was created on a old version of Xcode, you updated Xcode and then tried to do a submission to the app store.
Read the apple swift blog about binary compatibility and frameworks
You will also want to specify that your embedded content contains swift in the build settings:
EMBEDDED_CONTENT_CONTAINS_SWIFT
Enable this setting to indicate that content embedded in a target's product contains Swift code, so that the standard Swift libraries can be included in the product.

Running Uncrustify by selecting Behavior in Xcode does nothing

I installed Uncrustify as per the instructions here:
http://noiseandheat.com/blog/2012/01/uncrustifying-objective-c-source-in-xcode-4/
Used brew for installation and added new behavior in Xcode(4.3.2) preferences.
However running the behavior from the menu does nothing. What might I be missing?
For me https://github.com/tonyarnold/Xcode-4-Uncrustify-Automator-Services worked : Automator is used to create a workflow, which will be available in Xcode to format the selected code (The link above could describe a better way - I am just saying what worked for me...)
Thanks Thomas, resource provided by you was very useful and allowed me to add automator workflows into Xcode. Only problem is that script "Uncrustify Document then Re-Indent" is showing an error "System Events got an error: Access for assistive devices is disabled". Initially I sudo touch /private/var/db/.AccessibilityAPIEnabled to enable assistive devices but this did not help.
I found a thread on similar issue here: AppleScript - System Events Error : Access for assistive devices is disabled
fanaugen says:
The problem is not the assistive devices. AppleScript seems to incorrectly return that error code when it tries to access windows of a process that can never have any windows
and he suggest to rewrite script with some changes. I am not sure if it is actually the same issue here and it's first time I am having to deal with this type of script, so I am lacking of knowledge here. Do you have any advice? Did you have a similar issue?

How to Codesign Growl.framework for Sandboxed Mac App

I'm trying to submit a Mac app for Approval in the App Store, but linking with Growl is causing a validation error. I'm trying to re-codesign from the command line, but I'm getting the following error:
Ashs-MacBook-Pro:500px Uploader ash$ codesign -f -v -s "3rd Party Mac Developer Application: 500px Inc." ./Growl.framework/Versions/A
./Growl.framework/Versions/A: replacing existing signature
./Growl.framework/Versions/A: object file format unrecognized, invalid, or unsuitable
I've tried re-downloading the framework, but with no luck. Anybody see what I'm doing wrong?
Really strange, I've managed to resign the framework like this:
codesign -fs "3rd Party Mac Developer Application: Future Simple" Growl.framework/Versions/A/Growl
Growl.framework/Versions/A/Growl: replacing existing signature
(BTW: I'm working with Xcode 4.3.1 and Growl 1.3.1)
I just spent the day working through the "bundle format unrecognized, invalid, or unsuitable" error when codesigning a framework. In my case I'm using XCode 4.6.1 and I was trying to code sign Qt frameworks.
First note that the Apple documentation (TN2206) explicitly states that you need to code sign the versioned framework directory, not the library executable.
This is discussed further here:
How do you codesign framework bundles for the Mac App Store?
So, based on that, the command line in Ash's original question is correct. However I was getting the same error.
I did get it working with that command line. Here are the things that I had to do:
Make sure that you're using the correct version of CODESIGN_ALLOCATE. This is discussed in many of the answers here: iPhone Codesign object file format invalid or unsuitable If you can get XCode to sign an app then you can find the CODESIGN_ALLOCATE path in the build log.
Make sure that the versioned directory (./Growl.framework/Versions/A in the question above) contains Resources/Info.plist and that there is a link from Versions/Current -> Versions/A and that there is a link Resources -> Versions/Current/Resources at the top level of the framework bundle. I found that I could not sign the versioned framework directory without the Versions/A/Resources/Info.plist being present. You can read more about the correct structure of a framework here and here, or just take a look at some system frameworks to get an understanding about how they're supposed to be structured.
Further to the previous point, make sure that your symlinks in your framework bundle are structured correctly (Current links to numbered version, top level links to Current) as shown in the Apple docs. This won't affect code signing but your App will be rejected if you don't get this right.
Make sure that CFBundleExecutable is set to the correct name (the executable name) in your framework's Info.plist
Would it be better if we shipped the sdk unsigned? It'd be a simple change, I'm hesitant to do so now since it's been like this for a little while.
It looks like the error might have been trying to sign a bundle that was already signed; I fixed the issue by downloading the Growl framework source and compiling it with my own signature instead.
If I find a better answer that will work for frameworks for which you don't have the ability to compile, I'll post it here.

Google Api 64bit Objective-C

I want to implement in my Mac application the google API for uploading file on Gdocs, sadly I discovered that Google api for Objective-C are still in 32bit while my app is in 64bit with the new ARC support.
So before converting my app to 32bit I tried to build the google api in 64bit, I downloaded the .diff patch found here:
http://code.google.com/p/gdata-objectivec-client/issues/detail?id=30
and applied it.
Then I tried to rebuild the Google api in 64bit and it succeded (before there were errors), so I copied the Gdata framework in my project and I was able to build it without errors.
BUT, when I click play this is the error I retrieve:
dyld: Library not loaded: #loader_path/../Frameworks/GData.framework/Versions/A/GData
Referenced from: /Users/Xeo/Library/Developer/Xcode/DerivedData/GdocSync-fpcfhxbalzflkxdigudsndijtiol/Build/Products/Debug/GdocSync.app/Contents/MacOS/GdocSync
Reason: image not found
The framework is linked, I set it in the frameworks to link, soI don't really know how to do this, I would like to waste another bit of time before converting the app to 32bit!
EDIT: i was able to build it under xcode 4 with arc support only adding the sources into my app and building directly from there as explained in the google wiki.
No luck with the framework!
Try deleting the derived data from your app in the Xcode 4 organizer, give the target a good scrubbing and build again.

json-framework doesn't work with iPhone SDK 3.0

I can't seem to get my app to compile when using JSON-framework http://code.google.com/p/json-framework/ with iPhone SDK 3.0.
My app compiles fine for the simulator, but when I go to compile for my device I get a 'codesign error' code 1. I've followed all of the installation instructions correctly, and when I remove the 'Additional SDK' reference and 'Other Linker Flags: -Obj-C -ljson' it compiles just fine...but obviously I then can't use JSON in my app.
Any ideas?
You may want to just switch to the code version and not link in the static lib.
It should compile and work fine on 3.0.
On my own project, I too ran into this problem. I was not able to build my app for iPhone OS 2.x using the iPhone 3.0 SDK.
The fix was to set the following at the project level (Get Info):
BaseSDK to iPhone Device 3.0
iPhone Deployment Target to iPhone OS 2.x
Code Signing Resource Rules Path to the same 2.x plist (e.g. /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk/ResourceRules.plist)
The last bit allows a distribution (app store) build to code sign correctly... Otherwise you'll encounter an error "object file format invalid or unsuitable" since the code signer by default will use the same resource rules as the BaseSDK (i.e. 3.0), which is unsuitable for a 2.x app.
Also, be sure to clear any of the above settings at the target level (again, via Get Info).
Phew.
Codesign error means you do not have a valid provisioning profile for the device you are trying to compile to, using the current built settings.
Can you build and deploy sample apps to your phone?
I started using the lovely json-framework for the iPhone but then suddenly found that if I compiled for anything greater than 2.1 for a device, that it would pop up with:
Codesign error: “object file format invalid or unsuitable”
It took me a long time to figure out what was going on, but thanks to a blog post, the fix is this:
On the project settings, on the build tab, search for “Code Signing Resource Rules Path” and set “$(SDKROOT)/ResourceRules.plist” as its value.
I’m not sure how it works as it looks like that is the path it already has, but hey, it seems to work!
that solves the codesign error i was getting, but now I cant compile on 3.0 for some other reason. i'm going to try to link to the code rather than the library.
Sounds like an issue you would want to discuss with the developers, see the support group.
It seems like the code signing isn't extending to the framework. Have you tried linking the framework differently?
And for French persons, here is a tutorial too here too (en Français)
But for your problem I think it's not about JSON but more with your key developer.