Posts Tagged iPhone Development

Finding Xcode’s Pre-defined Macros for iOS Devices

I regret not making better notes about exactly why I was looking for a full list of the pre-defined macros Apple made available for iOS development.  I usually like starting an entry talking about why I was trying to solve a particular problem.  While I made a note to write up what I found, I did not note why I needed it at the time.  Assuming you are reading this because you need or might need such a thing, I’ll write on.

Some of the pre-defined macros are published in Apple’s documentation, but not all.  (Well, as far as I remember anyway.)  I feel the most confident that I didn’t miss one that could solve a problem when I get the list from the compiler itself.

While searching the internet I found instructions to use

I changed ‘i386’ to ‘armv6’ and ‘armv7’ but that failed on my setup.  I don’t really know if I messed something up in the /Developer folder or if this line just generally won’t work for ARM.

The error message mentioned a missing file and after finding it, I changed the above command to this:

For Xcode 3.2.5:

For Xcode 4.2.1

Change the “armv6” to “armv7” and vice-versa as needed.

Tags: , , , , ,

Solid Code: Mixing Objective-C and C++

If you’ve noticed that there’s been a long time between this post and the previous one,  you are right. My day job has been keeping me busy.  But that’s why I can get on with the topic: mixing legacy C++ with Objective-C.

After trying things a few ways,  I’m finding that one basic assumption difference between the languages can trip you up: the assumption about calling a method or function with an object pointer to zero (a.k.a. nil or null or NULL).

Since the C++ will generally be legacy code,  its natural for Objective-C objects to wind up containing pointers to C++ objects.  After that, its pretty easy to wind up calling C++ functions almost directly from accessors like:

This is functional,  but from a solid-coding standpoint,  it is too bug-prone and too hard to debug.  If the above statement crashes, which part of it failed?

Objective-C assumes that calling member methods with nil object pointers is OK.    (i.e., a nil ‘self’ pointer is not an error.)  Any such attempt just automatically returns zero.

C++ however, assumes that member functions will never be called against a NULL pointer.  (i.e., a NULL ‘this’ pointer.)  Any such attempt will probably crash an iPhone with EXC_BAD_ACCESS.

My point here is you should put the pointer into a variable, then call the function from that variable:

Now the language assumptions are clearly separated.  Nil pointers in the first line can be safely assumed to have zero method results. And the C++ in the second line can be more easily debugged if it fails.  (And we can easily check our C++ pointer for NULL before calling its function.)

The crash from the C++ code will most likely happen when the member function tries to dereference a member variable.  An instance’s member variable is held at an offset from the pointer, so if the pointer is zero, the member equates to an address that is near zero.  Addresses near zero are invalid on the iOS.

So there you go,  if you have to mix Objective-C and C++,  avoid mixing them on the same line.

Tags: , , , ,

XCode Giving Incorrect Error Messages after Upgrade to 3.2.2

A few days ago,  I was helping upgrade a Mac’s XCode environment from 3.1.4.   After the upgrade, the first attempt to build and run a project resulted in strange errors.  “Security Policy Violation”  came back from the device along with problems with the entitlements.

After much poking and prodding, I noticed that the Base SDK for the project was set to “iPhone OS 2.0 (missing)”.  The base SDK for the project was no longer available in XCode after the 3.2.2 upgrade.

Resetting the BaseSDK to 3.0 solved the issues and the build and run was fine.

Tags: , ,

iPhone Pattern: The ID Device?

I’ve seen stories lately that make me think another app pattern is emerging: iPhone as an ID. (Not news to you? Gotta love intelligent readers.)

It does make some sense.  In cases where serious identification is not crucial, the iPhone can be used.  With a full iPhone, you can bet people don’t just loan them out to people indiscriminately.   On days when I’ve forgotten my wallet, I still didn’t forget my iPhone.

Think about these:

  • Companies are sending account information, such as passwords or password reset info to the mobile phone recorded in the account.
  • RSA has a “SecurID” app for the iPhone.  Its used just like the cards and keychain dongles that give a code number once a minute.  That’s 2-factor authorization.
  • iPhone and iPhone apps are being used to pay for physical goods and services. A hotel reportedly issues iPod Touches to guests.  The guests uses them to order food and drinks by the pool and pay on the room account.  (They give the devices back at checkout time.)
  • Apps are used to exchange contact information.

Tags: , , , ,

iPhone Ad-Hoc distribution problems

Well,  an interesting bit of problem-solving today.

I sent a revision of an app to a client with ad-hoc distribution.  It installed just fine on one device, but would not install on the other. (The one that was going to be used to demo the product.) I double-checked that both device IDs were properly included in the provisioning profile.

After some quick re-reading, I thought the (cryptic) error might be that I forgot to send the .mobileprovision file along with the app.  One of the instruction lists showed installing the profile manually.  But when the file was emailed and isntalled, iTunes asked if it should replace the existing provisioning profile. It probably came from the app (which has a embedded.mobileprovision file in it.)

iTunes doesn’t show any information about installed profiles (that I could find) so it wasn’t clear if the provisioning profile was actually on the device.  A quick download of the iPhone Configuration Utility cleared that up.  It showed information similar to  XCode’s organizer, including the provisioning profile.

As it turns out, you can’t just send a .zip of your app straight to a Windows computer like you can on the Mac.   I haven’t seen an explanation anywhere, but it might be that the bundle contains files or folders with names that are not Windows-friendly.  Both contain a symlink file, but they seem the same.

The solution it seems is to process the app bundle into an .ipa file.  The easiest way to do this is to drop the bundle on iTunes. It will process the bundle into an ipa file.  Just control-click on the app to pull up the contextual menu and choose “Show in Finder”.   (Or go find it in the iTunes folder.)  Send that ipa file to your ad-hoc Windows users and they can drop it into their iTunes.

The errors from the iPhone log:

unknown mobile_installationd[1347] <Error>: 00808a00 install_embedded_profile: Skipping the installation of the embedded profile
unknown mobile_installationd[1347] <Error>: unrecognized status -67068 from codesigning library
unknown mobile_installationd[1347] <Error>: 00808a00 verify_executable: Could not validate signature: e8008001
unknown mobile_installationd[1347] <Error>: 00808a00 preflight_application_install: Could not verify /var/tmp/install_staging.Pav7Nw/foo_extracted/Payload/
unknown mobile_installationd[1347] <Error>: 00808a00 install_application: Could not preflight application install
unknown mobile_installation_proxy[1346] <Error>: handle_install: Installation failed
unknown mobile_installationd[1347] <Error>: 00808a00 handle_install: API failed
unknown mobile_installationd[1347] <Error>: 00808a00 send_message: failed to send mach message of 64 bytes: 10000003
unknown mobile_installationd[1347] <Error>: 00808a00 send_error: Could not send error response to client

Tags: , ,

SQLite Missing Functions in iPhone 2.x

While trying to improve my app’s memory usage, I tried to add a call to SQLite’s routine to release memory cache: sqlite3_release_memory().   But when I tried to build it, I got the following error:

ErrorDot“_sqlite3_release_memory”, referenced from:
-[AppDelegate applicationDidReceiveMemoryWarning:] in AppDelegate.o
symbol(s) not found
collect2: ld returned 1 exit status

Read the rest of this entry »

Tags: ,

iPhone Developer Group Meetings in Orlando

I was surprised recently to see how many groups are starting up around iPhone development in the Orlando area.  I’ll compile my list into a page and see how it works out.

I’ve attended two meetings and enjoyed both greatly.  The levels of focus, curiosity, and participation were great.  The discussions of just development challenges in general were also very good.

  • NSCoder Orlando (site twitter)   – meets every Tuesday
  • Mac & iPhone Developer Meetup (site twitter)  –
  • Orlando Cocoa-Heads  (site twitter)  – 2nd Tuesdays suggested, but still variable

The Panera’s restaurant downtime for the Mac & iPhone meetup group was pretty tough to find parking near, so go with a little extra time for that. Maybe take $5 or so in cash if you have to pay for a parking space.   That Panera’s does close at 8:30 pm.  While they are very gracious to people lingering, you won’t be able to get in or buy anything after that.

If you are more interested in a group for simply using the iPhone, check out the meetings of  the Florida Macintosh Users Group.  All the meetings wind up talking about iPhones at some point, but some will have different focus.

  • FLMUG main meeting (site twitter)
  • iPhone SIG (special interest group)  (site twitter)
  • FLMUG Business SIG (site twitter meetup)

Tags: , , , ,

Mysterious iPhone status bar icon?

Last night I was attending the iPhone SIG of the Florida Macintosh Users Group (FLMUG).

One of the members was asking about an icon in his status bar he couldn’t identify.  It looked like a landline telephone’s receiver with a keyboard underneath.  We scratched our heads for a minute until Phil said “wait, that’s gotta be the TTY setting”.  He quickly looked in Settings under “Phone” and yes, the TTY setting was on.  The icon went away when the setting was turned off.

Kudos to Phil for deducing the answer based on the “phone” and “keyboard” clues.

So today, I had to go lookup the other icons which may be displayed, just in case. 🙂  They are listed by Apple as “status icons” here:


Tags: ,

iPhone App Approval Took 12 Days

I got my first iPhone app,  ChronoGami, approved for download on the App Store.  And, the approval process did take 12 days from submission to approval.

There’s a lot more to the story than that of course.  I have worked on apps for other people that have shipped out through the App Store before ChronoGami.  But I began work on ChronoGami before I worked on those, so I still think of it as my first app.  I use it myself to track time on various bits of work and my life.   (I’ve got several upgrades to deliver when I finish testing already.)  I intend to be using ChronoGami exclusively for this in the near future. Adjusting to the iPhone keyboard still proves to be a challenge for note-taking.

An ironic part of the story that makes me laugh:  I checked the status of ChronoGami just before leaving for an interview to talk about possible Mac and iPhone work.  Late in the interview, during a break, I got online and checked again.  It had been approved!  Now I had one more point to talk about in the rest of the interview.  🙂

Tags: ,

Getting to Build Options in XCode for iPhone Projects

Choose one of the "Base SDK" members.

Choose one of the "Base SDK" members from the "Overview" popup in the project window.

Been frustrated with getting the proper compiler options turned on and off for iPhone projects because they don’t show up in the build settings?  Me Too.

Many thanks to Rick Maddy for posting the answer to this on so I can finally access the “GCC 4.0 – Code Generation” and “GCC 4.0 – Language” sections correctly.

To see these entries in the settings window,  you must first go to the “Overview” popup menu in the project window and select one of the entries that correspond to the “Base SDK” as specified in the build settings.  If your project’s “Base SDK” (wording used by XCode 3.1.3) is a device, you must select one of the device entries.

Note that for XCode version 3.1.2.  this was referred to as  “(Project Setting)”.  If later or previous versions have different wording, please let me know and I’ll update this.

If any other entry from the popup’s “Active SDK” section is chosen, you will not see these through either method of accessing the build options.   This is typically my problem as the selection spends most of the time on a “Simulator” setting during development.

With another entry, you may see some flags show in the “User Defined” section at the bottom of the build options.  You can still set options with these (as I did before finding out this information.)

The "Base SDK" project setting.

The "Base SDK" project setting.

This is just what I needed to address problems like:

“error: ‘for’ loop initial declaration used outside C99 mode”

Tags: ,