README.iOS
changeset 7190 11612d544fcd
parent 6654 2ecfb25be1e2
     1.1 --- a/README.iOS	Sat May 18 09:35:09 2013 -0700
     1.2 +++ b/README.iOS	Sat May 18 12:48:50 2013 -0700
     1.3 @@ -55,6 +55,69 @@
     1.4  5.  Delete the contents of main.m and program your app as a regular SDL program instead.  You may replace main.m with your own main.c, but you must tell XCode not to use the project prefix file, as it includes Objective-C code.
     1.5  
     1.6  ==============================================================================
     1.7 +Notes -- Application events
     1.8 +==============================================================================
     1.9 +
    1.10 +On iOS the application goes through a fixed life cycle and you will get
    1.11 +notifications of state changes via application events. When these events
    1.12 +are delivered you must handle them in an event callback because the OS may
    1.13 +not give you any processing time after the events are delivered.
    1.14 +
    1.15 +e.g.
    1.16 +
    1.17 +int HandleAppEvents(void *userdata, SDL_Event *event)
    1.18 +{
    1.19 +    switch (event->type)
    1.20 +    {
    1.21 +    case SDL_APP_TERMINATING:
    1.22 +        /* Terminate the app.
    1.23 +           Shut everything down before returning from this function.
    1.24 +        */
    1.25 +        return 0;
    1.26 +    case SDL_APP_LOWMEMORY:
    1.27 +        /* You will get this when your app is paused and iOS wants more memory.
    1.28 +           Release as much memory as possible.
    1.29 +        */
    1.30 +        return 0;
    1.31 +    case SDL_APP_WILLENTERBACKGROUND:
    1.32 +        /* Prepare your app to go into the background.  Stop loops, etc.
    1.33 +           This gets called when the user hits the home button, or gets a call.
    1.34 +        */
    1.35 +        return 0;
    1.36 +    case SDL_APP_DIDENTERBACKGROUND:
    1.37 +        /* This will get called if the user accepted whatever sent your app to the background.
    1.38 +           If the user got a phone call and canceled it, you'll instead get an SDL_APP_DIDENTERFOREGROUND event and restart your loops.
    1.39 +           When you get this, you have 5 seconds to save all your state or the app will be terminated.
    1.40 +           Your app is NOT active at this point.
    1.41 +        */
    1.42 +        return 0;
    1.43 +    case SDL_APP_WILLENTERFOREGROUND:
    1.44 +        /* This call happens when your app is coming back to the foreground.
    1.45 +           Restore all your state here.
    1.46 +        */
    1.47 +        return 0;
    1.48 +    case SDL_APP_DIDENTERFOREGROUND:
    1.49 +        /* Restart your loops here.
    1.50 +           Your app is interactive and getting CPU again.
    1.51 +        */
    1.52 +        return 0;
    1.53 +    default:
    1.54 +        /* No special processing, add it to the event queue */
    1.55 +        return 1;
    1.56 +    }
    1.57 +}
    1.58 +
    1.59 +int main(int argc, char *argv[])
    1.60 +{
    1.61 +    SDL_SetEventFilter(HandleAppEvents, NULL);
    1.62 +
    1.63 +    ... run your main loop
    1.64 +
    1.65 +    return 0;
    1.66 +}
    1.67 +
    1.68 +    
    1.69 +==============================================================================
    1.70  Notes -- Accelerometer as Joystick
    1.71  ==============================================================================
    1.72