Archive for Snippets

iPhone Coding Snippet – In Application Emailing

November 18th, 2009 Posted by: - posted under:Snippets - 44 Comments

A lot of applications you see have an email button. When you click it then it will leave the application and take you to the Mail application. It can get really annoying leaving the application and then going back in after your done sending the email. This is just a great way to show off your app and make your app look more professional and make it easier on the user by filling in the To and Subject for them. …


    Code Snippet – Quickly Find The Documents Directory

    September 9th, 2009 Posted by: - posted under:Snippets - 9 Comments

    As many of you may have seen by now, there are quite a few ways to find the documents directory on the iPhone. For those of you who don’t know, the documents directory of an app is the location where you should save your application data. While finding the documents directory is a trivial task, it is very important when coding most applications. Apple has provided quite a few ways for resolving the path to this directory.
    If …


      Programmatically Getting a Screencapture of any UIView

      July 27th, 2009 Posted by: - posted under:Snippets - 29 Comments

      Hey guys. This post is in response to a comment made in my last post about NSTimers. Techy asked if we could do a post on how to take screenshots programmatically using the iPhone SDK. For this minor project we will be creating a small web browser application that will start at, and have a button on a toolbar at the bottom to take a picture of the web view and save …

        READ MORE

        NSTimer: The Poor Man’s Threading – Code Snapshot

        July 23rd, 2009 Posted by: - posted under:Snippets - 34 Comments

        Hey guys. So usually the posts we put up here involve screencasts and presentations, but we are going to start also posting small less time consuming pieces for the site. Today I bring to you a small project involving NSTimers. Today we are going to build an app that represents a horse race. We will create a view with 6 small UIView squares with a blue background at the bottom of the screen, we will use a timer to move …

          READ MORE

          Code Snippet: Prevent The iPhone From Sleeping

          July 22nd, 2009 Posted by: - posted under:Snippets - 7 Comments

          The code below will prevent the iPhone from dimming its screen and ultimately going to sleep. Use it wisely as you don’t want your application becoming notorious for being a battery hog

          [UIApplication sharedApplication].idleTimerDisabled = YES;

          Happy iCoding!

            READ MORE

            iPhone Programming Tutorial – Using openURL To Send Email From Your App

            February 20th, 2009 Posted by: - posted under:Snippets - 98 Comments

            Have you been curious about how to open from your applications to send contact email? Today, I will be teaching you how to do just that. We will even be pre-filling the subject, to line, and body of the email.
            This is a great way to to put a contact or bug report button on your app. I’m going to start with a simple UI that I created. I’m not going to discuss how it was created …

              READ MORE

              Loading data from .plist files

              February 14th, 2009 Posted by: - posted under:Snippets - 20 Comments

              Saving and Reloading from .plist files…
              A great way to store dictionary data that does not change during runtime is in a .plist file. Say you want to organize some data hierarchically or you want to store the navigation structure of a drill-down somewhere more convenient (see drill-down save example in apple docs), then a .plist file is a great way to go.
              Here’s a quick example of how to restore data from a plist file. I’ll use a plist …

                READ MORE

                Finding Substrings in Objective-C

                November 3rd, 2008 Posted by: - posted under:Snippets - 14 Comments

                It’s times like this, that I miss ruby.
                I’m checking a url to see if it has a substring. It would be so easy if this was ruby:
                absolute_url.match(/my regex/).any?
                In Objective C, you have to use rangeOfString which returns a range. If I were to run this on the string “the quick brown fox” with an argument of “brown” it would return {10,14}. If it’s not found, it would return {NSNotFound, 0}. Let’s use that to check to …

                  READ MORE

                  iPhone: applicationDidFinishLaunching & handleOpenUrl

                  November 3rd, 2008 Posted by: - posted under:Snippets - 6 Comments

                  You use the applicationDidFinishLaunching method to kick off your application. This event fires automatically on your delegate whenever your app launches.
                  If your app launches from a special url schema (tel://, http://, mailto://), then another event is fired:
                  As you might have noticed in the LaunchMe sample project that ships with Xcode, these two methods will most likely conflict.
                  Move the functionality from applicationDidFinishLaunching and put it in another method, like postLaunch. Then add a member variable to the application delegate …

                    READ MORE