Blog

Tag Archives: Cocoa

Links for October 25th through January 23rd

Links for October 25th through January 23rd:

Also tagged , , , | Comments closed

Error -12986 and you

A customer recently got in touch with me with an odd problem — Talkie for iPhone was going silent on him. After a little diagnosis, it turned out the audio system was throwing up an undocumented error — -12986 — while starting up on his iPod Touch.

Some googling turned up this thread on Stack Overflow, which presented a solution for the AVAudioSession framework: It turns out, on recent SDKs (somewhere equal to or above 3.0), the audio system will refuse to start up if the session is set to a recording mode, with no input device available, spitting out this error. Alas, the error isn’t listed anywhere that I could find.

So, the way to fix it is to check whether there’s an input device available, then choose an audio category accordingly:

OSStatus status;
 
UInt32 inputAvailable=0;
UInt32 size = sizeof(inputAvailable);
AudioSessionGetProperty(kAudioSessionProperty_AudioInputAvailable, 
                        &size, 
                        &inputAvailable);
UInt32 sessionCategory;
if ( inputAvailable ) {
    // Set the audio session category for simultaneous play and record
    sessionCategory = kAudioSessionCategory_PlayAndRecord;
} else {
    // Just playback
    sessionCategory = kAudioSessionCategory_MediaPlayback;
}
 
status = AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,
                                  sizeof (sessionCategory),
                                  &sessionCategory);    
checkStatus(status);

It’s probably a good idea to respond when input becomes available or goes away, so add a property listener too:

void inputAvailablePropertyListener (void                      *inClientData,
                                     AudioSessionPropertyID    inID,
                                     UInt32                    inDataSize,
                                     const void                *inData) {
    if ( inID = kAudioSessionProperty_AudioInputAvailable ) {
        UInt32 *inputAvailable = (UInt32*)inData;
        UInt32 sessionCategory;
        if ( *inputAvailable ) {
            // Set the audio session category for simultaneous play and record
            sessionCategory = kAudioSessionCategory_PlayAndRecord;
        } else {
            // Just playback
            sessionCategory = kAudioSessionCategory_MediaPlayback;
        }
 
        OSStatus status = AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,
                                                   sizeof (sessionCategory),
                                                   &sessionCategory);    
        checkStatus(status);
    }
}

then:

// Listen for audio input availability
status = AudioSessionAddPropertyListener(kAudioSessionProperty_AudioInputAvailable,
                                         inputAvailablePropertyListener, 
                                         NULL);
Also tagged , | Comments closed

Links for May 21st through June 2nd

Links for May 21st through June 2nd:

Also tagged , , , , , | Comments closed

Links for March 17th through April 24th

Links for March 17th through April 24th:

  • XSD Schema XML Validator A XSD Schema validator in Java, provides lots of useful information; use it with a schema and an xml instance
  • Three20 Three20 is a collection of iPhone UI classes, like a photo viewer, and general utilities, like an HTTP disk cache. Three20 is derived from the Facebook iPhone app, which is one of the most downloaded iPhone apps ever.
  • CSS Decorative Gallery …How to decorate your images and photo galleries without editing the source images. The trick is very simple. All you need is an extra <span> tag and apply a background image to create the overlaying effect.
  • Comet (programming) – Wikipedia, the free encyclopedia Comet is a neologism to describe a web application model in which a long-held HTTP request allows a web server to push data to a browser, without the browser explicitly requesting it
  • Cocoa Is My Girlfriend » Cocoa Tutorial: awakeFromNib vs applicationDidFinishLaunching A very good overview of the 'startup' procedure for objects stored in IB nib/xibs.
Also tagged , , , , , , | Comments closed

Links for March 6th through March 16th

Links for March 6th through March 16th:

Also tagged , , , | Comments closed

Podcast interview with Dan Grigsby of Mobile Orchard on Loopy’s development

iphone-loopy-mobileorchard.pngLast Thursday I did an interview with Dan Grigsby from Mobile Orchard; the interview is now online.

Highlights from this interview include: From UIView to OpenGL: the seven different implementations it took to finalize its unique — and Best App Ever award-nominated — UI. From audio-queues to Remote IO: the four different architectural approaches he tried before finalizing audio subsystems. The travails of trying to implement echo cancelation. The business of making a living off of a $10 app

Listen to it here, or subscribe in iTunes (30 min.)

Also tagged , , , , | Comments closed

Understanding error codes

Just in case there’s someone else that didn’t know this, when one gets an error code from one of the iPhone/OS X SDKs with no other information available, it can usually be looked up in the MacErrors.h header. Just open a terminal, type:

open -h MacErrors.h

Then do a search for your error code and you’ll hopefully find a corresponding macro name that gives some indication of what went wrong.

Failing that, if you have an inkling of where the error occurred (eg. the AudioToolbox framework), then you can often find the error defined within the framework’s headers:

$ grep -r '10863' /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.1.sdk/System/Library/Frameworks/AudioToolbox.framework/ /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.1.sdk/System/Library/Frameworks/AudioToolbox.framework/Headers/AUGraph.h: kAUGraphErr_CannotDoInCurrentContext = -10863,

That was, type in Terminal grep -r 'the error code', then drag the framework straight from XCode into the Terminal, where the path will be inserted.

Also tagged , | Comments closed

Links for February 10th through February 27th

Links for February 10th through February 27th:

  • TinEye Reverse Image Search TinEye is a reverse image search engine. You can submit an image to TinEye to find out where it came from, how it is being used, if modified versions of the image exist, or to find higher resolution versions.
  • Traffic Shaping in Mac OS X | Mac Geekery "…Create several pipes that have a set bandwidth and other properties for all packets that get filed into them; you then add queues to those pipes that determine what priority certain requests will get in that pipe; then you add actual firewall rules to identify packets and file them into queues."
  • Brandon Walkin » Introducing BWToolkit BWToolkit is a BSD licensed plugin for Interface Builder 3 that contains commonly used UI elements and other useful objects. Using these objects is as simple as dragging them from the library to your canvas or document window. In particular, "No Code" preferences window and tabbed sheets.
  • Aussie iPhone app developers and the IRS? Discussion about tax details for Australian iPhone developers. It appears the advice from Apple on the tax form is incorrect for sales on the App Store.
  • google-toolbox-for-mac – How to do iPhone unit testing This is a quick tutorial on doing iPhone unit testing using the facilities in the Google Toolbox For Mac
Also tagged , , , , , , | Comments closed