iPhone App References by chope1470


More Info
									TheBunny's #IphoneDev Faq v.25

Funny somehow Google found this FAQ on the server and now Im getting a lot of emails :)

Now that the NDA is lifted that is just fine.

Any how feel free to email with questions, ideas, errors or anything else you want in the FAQ at

You can also find me on IRC freenode / #iphonedev as TheBunny

Also My Game company is www.plaidworld.com

My On going iphone game development blog is at www.bang2d.com

PS: Send anyone interested in investing in an iPhone/Mobile game company our way :)
        Our engine is already up and running on Mac/Win/Linux and iPhone.


        Do I have to use ObjC on the Phone?

                 You can freely use C / C++ on the phone.
                 You still need to use ObjC to talk to the Cocoa APIs.
                 Feel free to wrap C++ code in ObjC call backs / events.

                 This page provides a summary of how Objective-C is implemented in C
                 using Apple's Objective-C runtime. Meaning you could call methods on ObjC objects
                 purely using C / C++ if you really wanted to.


        How do I turn on ObjC++
                Change your file extensions to .mm

        Does Garbage Collection work on the phone?

Learning Cocoa / ObjC:

        Iphone Dev web sites

        Learning Objective C a primer

        MyFirst Iphone app:

                 Under the "Getting Started" Tab
                         Read "Creating a iPhone Application"

        Introduction to The Objective-C 2.0 Programming Language:



                 Cocoa(R) Programming for Mac(R) OS X (3rd Edition) (Paperback)
                 by Aaron Hillegass (Author)
       Programming in Objective-C (Developer's Library) (Paperback)

Developer Program:

1. 1. I just applied for the iPhone Dev program how long till I get in?
        Well thats a trick question... back in april I got in, in 2 weeks and
        I had a LLC and Company account.

        Other people still report not being accepted since the very beginning.

        Since the iPhone 2 launched I believe most developer world wide are getting in pretty fast.

2. I just paid apple 99$ how long will I have to wait till I get my certs?

   A: Maybe 24 hours.

What do I need to be able to test on the phone?

        You need to to pay apple 99$ after which you will be able to generate a provisioning
        certificate that will allow you to run code on the phone.

License Agreement:

        Will apple let me to this on the ???
                For starters read the SDK license agreement its written in very plain English.

                a. You did not actually read the license did you?
                b. You are talking about license section 3.1
                c. The sections of the license you are talking about address 2 issues.
                        First is the use of plug ins or any kind of plug in like system.
                        Second you will not run any "DOWNLOADED" script.
                d. Mouse House my games is 95% Lua and is currently for sale in the App store.



        How do I simulate multi-touch?

                 Hold down option

                 If you hold option in the simulator,
                 you can pinch, as always,
                 but if you hold shift,
                 you can change the center point of the pinch.

        How do I swipe?

                 You can also hold shift and while holding it do a two finger swipe.




                 CPU - 600 mhz ARM underclocked to 410 mhz
                 FPU - YES use it!
                 GPU - PowerVR MBX Lite 3D [24] with 24 MB of shared VRAM
                 Screen 480x320Â px, 3.5Â in (89Â mm), color LCD, 3:2 aspect ratio
                 Camera 2.0Â megapixel
                 Memory 128Â MB DRAM[26]
                 Storage Flash memory 4, 8, or 16Â GB

         How much free RAM do I really have to use?
                 Apple told me about 40 MBs.
                 If you have a better idea tell me?


         What version of GLES is on the phone:
                 OpenGL ES v1.1

         Game code:
                 GLSprite ( on web site )
                 CrashLanding ( on web site )
                 Touch Fighter 2 ( handed out at WWDC ask nicely on IRC maybe )

         What is the fastest way to draw on the iphone?

         Best Practices for the GPU?

                 Get the
                 POWERVR MBX 3D Application Development Recommendations
                 and POWERVR Technology Overview



                The OpenGL Red Book or NEHE is all you really need to learn GL
                and most of normal GL translates directly to GLES

                You can order the red book USED from amazon

                 or here is at least 1 free HTML copy online.

                 Possibly a much better GL book with all the same stuff and a lot more is
                         OpenGL(R) SuperBible:



                 NeHe ( general OpenGL )

         iPhone Game Engines:

                Shiva 3D
                           Lua based 3D IDE host app is windows only(?)
                           Looks Cool tho

                 2D engine for iphone using python
                                  the PC/Mac/Linux coded in python (it doesn't work on iPhone)

                                   iPhone version coded in objective-c

                 With the NDA lifted libSDL is coming to iPhone

                CVS http://www.libsdl.org/cgi/viewvc.cgi/trunk/

        Unity3D - excellent mac/win game engine coming to iphone this week.
                I can highly recommend this one. I work with ith daily doing fulltime contracting work.


        Torque for iphone.

                Interestingly Oolong 3D game Engine below says iTorque uses it.
                I have no idea what Garage Games actually added on top of Oolong

       Oolong 3D game Engine
               Open Source
               Used in this game http://sourceitsoftware.com/zombie.html

        Here is another open source engine that looks good.


                        Games Made with it are at: http://sio2interactive.com/GAMES.html

                        IRC channel is: sio2

How do I load a texture?
        See any of the above source code...
        There used to be a class that both loaded textures and could draw quads for you.
        I used it as a basis for my quad based engine.
        The code is plenty fast.

How do I draw a tile/quad?
        See GLSprite code.

How do I play sounds?
        Use OpenAL
        See CrashLanding for code.


How Do I play music?

       See touch fighter 2 code SoundEngine.cpp

       AudioQueue for streaming audio music


        Also ins SDK 2.2
                There is a new AV frameworks that lets you play music in like 4 lines of code

        Touch Fighter 2 code.

       Speed issues:
               I solved that wifi throttling back providing high latency by sending a udp packet out e
               If you top >100ms, the wifi power saves and you get ping times to the ipod touch of upt
         Using GL and cocoa views/layers at the same time:
                 See how the prefs are done in the Touch Fighter 2 code.

         Whatshould I set my timer to?

                 Don't use a timer.
                 Use a thread instead for the main game loop.

                 In some recent verison of the SDK the issues with threading GLES were fixed.

                 Your game loop should look something like this and might get a nice +10 FPS from useing
                 threads vs Timers.

                 - (void) applicationDidFinishLaunching:(UIApplication*)application{

                                 // SET UP GLOBAL
                                 the_app = self;

                                 [ self my_setup ];

                                 // TIMER
                                 //[ NSTimer scheduledTimerWithTimeInterval:( 1.0 / kFPS ) target:self selector:

                                 // START THREAD
                                 [NSThread detachNewThreadSelector: @selector( run_bang2d_threaded: ) toTarget:s


                 - (void) run_bang2d_threaded:(AppController*)sender {

                         NSAutoreleasePool*        pool = [ NSAutoreleasePool new ];

                         // SET CURRENT GL CONTEXT FOR THREAD
                         [ sender->_glView setCurrentContext ];

                         // RUN SDL / LUA LOOP
                         bool game_over = false;

                         // TERMINATE MAIN GAME LOOP TIMER
                         while( game_over == false ){

                                 game_over = iphone_main( &iphone_events );


                         [pool release];


                 // OLD
                 a LOT higher then your actual desired max frame rate.
                 If you go to high the iphone will not get input. Say 1000 FPS.
                 If you go to low you will actually lose FPS while waiting for the timer to resume.
                 My games is currently set to around 500 fps.
                 If I set it to a steady 30 FPS or even 60 I lose an actual 5 FPS.
                 YMMV of course so play with it.


                 Are the preferred image format on the iPhone.

5 of 9                                                                                          7/22/10 2:58 PM
               But they get converted by xcode.

               All your PNGs get converted to BGRA with Premultiplied alpha
               its basically an optimization to make images draw fastest
               but that only really applies if your using UIKit to draw them.

               So if you are using a PNG lib to load them instead of the iPhone APIs you need to
               add the build setting IPHONE_OPTIMIZE_OPTIONS=-skip-PNGs
               to any target that doesn't want the PNGs modified

               Ok Here is how you do that...

                       Go to your projects build settings.

                       In the lower left hand corner is a menu you icon that looks like a GEAR

                       Choose Add User-Defined Setting

                       Name the setting: IPHONE_OPTIMIZE_OPTIONS

                       Set the Value to: -skip-PNGs

                       Do a clean build and your good to go as far as I can tell.
                       I checked my bundle here and it worked.

                       Im not sure if you will have issues cause the icon is also not compressed and neither i

               more notes...

              1. Rename your images to something else (eg. .ppng), and the XCode packaging tool will ignore y
              2. According to the following link (http://www.imgtec.com/powervr/insider/sdk/KhronosOpenGLES1x
                      you need to add the following build settings definition for each target.
              3. Teach your PNG decoder to handle Apple's CgBI format.
              4. Use the Cocoa UIImage classes or the Texture2D.m class.

              EVEN More notes

                       Is it possible to set an iPhone XCode project to skip the 'CompressResources' build ste
                       Specifically, I want to skip the stage where it runs pngcrush on all of my .png files,
                       of which don't survive the experience in a form which my app can read.
                       Edit: the version of pngcrush used creates png files which contain a non-standard
                       private' chunk which explicitly prevents decoding. I've modified my png reader to handl
                       files, but I'd still like a per-project method of skipping this step. One of the other
                       of pngcrush is that it doesn't save the colour value of transparent pixels, so alpha-ed
                       textures show fringing at smaller mip levels.
                       The iphone png format is described here: http://modmyi.com/wiki/index.php/Iphone_PNG_im
                       Skip the CgBI chunk
                       Skip the zlib headers
                       Swap BGR to RGB channel order

                       Edit: It appears it also premultiplies the alpha, so:
                       Divide by alpha

       LandScape Mode:
               How do I get my GL coordinate system in landscape mode?
                       Rotate your Camera -90

       How do I open a URL in Safari from my app?

              [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

         Theres at least 2 libs Im aware that you can slap in your App and track users and metrics
         like time used and just about anything else you want like... how many users finished your game.

                 Nice easy to use lib for tracking metrics in your app Im told.

                 This site also lets you see global itunes Rankings for you app and not just itunes top 100.
                 It also lists your rank over time.

                 See Mouse House for instance. http://www.mobclix.com/appstore/app/role-playing/mouse-house


         Theres a few sites that let you view all your itunes reviews world wide.



Sales Figures:

         Mouse House Sales

         Payday Roulettes



Ad Based Revenue:




Sound Samples:

         Good FREE sound sample sites.

         // NO LONGER FREE AS OF DEC 7th MEH :(





         iphone tip of the day: start the simulator from the command line
         with MallocStackLogging=1,
         run app from xcode as usual, use leaks against your app's pid
         to get much more useful results than the crappy instruments stuff


         // To change the title of the back button when using a UINavigationItem, use this undocumented call:
          UINavigationItem *navCon = [self navigationItem];
          [navCon setBackButtonTitle:@"Cancel"];

          // This call works, but is not in the header, thus causing a "may not respond to" warning. Make the war

          @interface UINavigationItem (Hacks)

          - (void)setBackButtonTitle:(NSString*)title;



To get the MinimumValueImage and MaximumValueImage to work with PSSliderSpecifier,
I had to open the Settings.bundle in the Finder using "Show Package Contents" and copy the png files in there.
Size didn't seem to make a difference, smaller ones worked OK.
The image files need to be in the Settings.bundle.
I could not get them in there using Xcode, had to do it by hand.

From: Â http://forums.macrumors.com/showthread.php?t=537644


IAlertView, UIAlertSheet and UIAlert run non-modal
To get them modal, do this:
//We're exposing a private method (undocumented)

@interface UIAlertView (Synthesize)

- (void)setRunsModal:(BOOL)modal;


  and then call: Â [alertView setRunsModal:YES] Â    before you "show" the alertView


 it's really cool
Detects memory leaks
and wrong code.
Stuff that "leaks" and xcode miss
It works at the llvm level
Then, put this script in your project
cd ~/Desktop/Projects/Svn/TouchPhysics
rm -rf build
~/Desktop/OSX\ Development\ Tools/Clang/scan-build  -k -V xcodebuild
(obviously change the paths)
Then "Clean your Project" and recompile by running this script instead
It will then popup the errors in Safari
YOu don't want to run it on every build (because it takes a little longer)
But just run it occasionally as you build stuff and want to do the check
It's a static checker, will find missing releases
Things like variables being reassigned before they are used (i.e. redudant code)
Pretty cool
Works great for iphone development too


Quentarez:   here's a great tip:
Quentarez:   when creating a draggable view, animated the update of the position with a .01 animation
Quentarez:   CGPoint touchLocation = [touch locationInView:[self view]];
Quentarez:   [UIView beginAnimations:nil context:nil];
Quentarez:   [UIView setAnimationDuration:.01];
Quentarez:   [UIView setAnimationBeginsFromCurrentState:YES];
Quentarez:   [[viewTouch view] setCenter:touchLocation];
Quentarez:   [UIView commitAnimations];
Quentarez:   if you don't animate it, it's very jerky
Quentarez: with this it's smooth as silk

To top