title: detect when shakes an iPhone
body: <p>i have questions regarding the shake detection that posted here before,
  here is a reminder:</p>
  
  <p>"Now ... I wanted to do something similar (in iPhone OS 3.0+), only in my case I wanted it app-wide so I could alert various parts of the app when a shake occurred. Here's what I ended up doing.</p>
  
  <p>First, I subclassed UIWindow. This is easy peasy. Create a new class file with an interface such as MotionWindow : UIWindow (feel free to pick your own, natch). Add a method like so:</p>
  
  <pre><code>- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
      if (event.type == UIEventTypeMotion &amp;&amp; event.subtype == UIEventSubtypeMotionShake) {
          [[NSNotificationCenter defaultCenter] postNotificationName:@"DeviceShaken" object:self];
      }
  }
  </code></pre>
  
  <p>Now, if you use a MainWindow.xib (stock Xcode template stuff), go in there and change the class of your Window object from UIWindow to MotionWindow or whatever you called it. Save the xib. If you set up UIWindow programmatically, use your new Window class there instead.</p>
  
  <p>Now your app is using the specialized UIWindow class. Wherever you want to be told about a shake, sign up for them notifications! Like this:</p>
  
  <pre><code>[[NSNotificationCenter defaultCenter] addObserver:self
  selector:@selector(deviceShaken) name:@"DeviceShaken" object:nil];
  </code></pre>
  
  <p>To remove yourself as an observer:</p>
  
  <pre><code>[[NSNotificationCenter defaultCenter] removeObserver:self];
  </code></pre>
  
  <p>questions:</p>
  
  <ol>
  <li>where to put the notifications (i have a view based app) ?</li>
  <li>do i have to remove myself as an observe, what does it mean ?</li>
  <li>what is the if statement that i use to check if the shake accrued?</li>
  <li>how can i know if the shake event know it is "already in progress" ?</li>
  </ol>
  
  <p>thanks.</p>