• 12 Jan 2009

    Dear Lazyweb,

    When running in the foreground, my iPhone app occasionally uses an alert to get the user’s attention. If the Ring/Silent switch is set to silent mode, the phone will vibrate (kSystemSoundID_Vibrate); otherwise a sound is played.

    It appears as though the iPhone SDK limits me to playing audio supplied by my application only:

    Picture 3.png

    IMG_0001.PNGI was unable to find any explanation for this limitation of the AudioToolbox Framework on the google. Does anyone out there know what the justification might be? Note that Apple’s applications seem to be able to use system sounds (presumably using the same AudioServicesPlaySystemSound or AudioServicesPlayAlertSound API calls exposed to us), as shown in this screenshot of the Alarm Clock application.

    Update:

    It looks like I’m able to use an NSDirectoryEnumerator to get the contents of /Library/Ringtones/ on the phone, but if I try to load one of these files using AudioServicesCreateSystemSoundID() it fails with OSErr -1500 (Operation could not be completed). Sandboxing… Thanks to Steve Makofsky for his help.


  • 23 Dec 2008

    Note to myself on going from the simulator to getting an application running on my iPhone:

    1. Select “Get Info” for the target (not the project) and go to the Build tab. Change the Code Signing Identity for Any iPhone OS Device to the provisioning profile you downloaded and installed from the Apple iPhone Developer Portal.

    2. Edit the `Info.plist` for your project. Change the Bundle Identifier to the App Identifier you registered with the Portal, minus the prefix. For example, my App Identifier is `123456789A.net.jakesprouse.*`; I changed the Bundle Identifier to `net.jakesprouse.${PRODUCT_NAME:identifier}`.

    3. Under the Project menu, set the active SDK to the Device entry with the desired OS.

    4. Build and Go.


  • 22 Dec 2008

    Dear Lazyweb,

    I finally got registered for the iPhone app developer program. I created a certificate for “iPhone Developer: Jake Sprouse”, uploaded it to Apple, approved it, and downloaded it into my Keychain. I registered the Device ID of my iPhone on the Apple website. I created an App ID for all jakesprouse.net applications (it’s of the form NNNNNNNNNN.net.jakesprouse.*). And I created a provisioning profile with the certificate, Device ID, and App ID.

    In my XCode project, I changed the “Code Signing Identity” field to “iPhone Developer: Jake Sprouse” under my provisioning profile in the drop-down. And I changed the “Bundle identifier” field of my Info.plist to NNNNNNNNNN.net.jakesprouse.${PRODUCT_NAME:identifier}.

    Now, when I build it, I get the error message: /Users/jakes/src/MyApp/build/Debug-iphoneos/MyApp.app: object file format invalid or unsuitable.

    If I build a second time, it works, but when it goes to install the app, the Organizer window tells me “The Info.plist for application at /Users/jakes/src/Sac4iPhone/build/Debug-iphoneos/Sac4iPhone.app specifies a CFBundleExecutable of (null), which does not exist“.

    If I build a third time, I get the object file format error again (and so on…).

    Searching Google on codesign + "object file format" is not being very helpful. Anyone out there have any ideas?


  • 22 Apr 2008

    [c]
    unsigned char t0, t1;
    unsigned int diff;

    t0 = 0;
    t1 = 255;

    diff = (unsigned int)(t0 – t1);
    printf(“difference: %xn”, diff);
    [/c]

    Intuitively, I would think that the result of the subtraction would be an unsigned char with value 0x01, which then would get converted to an unsigned int with value 0×00000001 (assuming a 32-bit platform).

    Instead, when the program is compiled and run, the output is:

    difference: 0xffffff01

    Turns out that my compiler is actually doing the right thing here, but C is playing tricks on me.

    The C standard has a concept of integer rank. long long has greater rank than long which has greater rank than int, which has greater rank than short, which has greater rank than char. Unsigned types have the same rank as their signed counterparts. Note that even if two integral types have the same size in bits, their rank is different.

    For arithmetic operations, the standard specifies that operands of integral data type are promoted to integer rank when their rank is less. Historically, there were two ways of doing so, called unsigned preserving and value preserving. The former simply converts all unsigned chars and shorts into unsigned ints. The latter converts them to signed ints if they are smaller and unsigned ints otherwise (i.e. if short and int are the same size, unsigned shorts will be converted to unsigned ints).

    In 1974, Kernighan and Richie’s The C Programming Language set the original C standard, and specified the unsigned preserving method. But in 1989 the first ANSI C standard switched (after much debate) to the value preserving method, because it reduces the number of situations in which the result of an expression is questionably signed, meaning it could intuitively be interpreted either way. More detail on this distinction can be found in Section 3.2.1.1 of Rational for the ANSI C Programming Language.

    So, in the example above, t0 and t1 are promoted to signed ints before being subtracted. On my machine, ints are 32 bits, so the resulting difference is a signed int of value 0xffffff01 (-255).

    This is then converted to unsigned int; the C standard specifies this conversion in an interesting way: “…the value is converted by repeatedly adding or subtracting one more than the maximum value that can be represented in the new type until the value is in the range of the new type.” In a twos-complement system, this is equivalent to leaving the bits unchanged. In our case, this means that the new value is -255 + 4294967296 = 4294967041 = 0xffffff01.

    The correct way to cause the desired wrap of in our example is to insert an explicit cast of the subtracted result back to unsigned char:

    diff = (unsigned int)(unsigned char)(t0 - t1);

    This produces the intended result:

    difference: 0x00000001


  • 05 Aug 2007

    This search engine for Firefox (and its ilk) browsers will search the Seattle Public Library’s catalog.

    Click here to install the plug-in.

    picture-3

    Happy searching!