Note that there are some explanatory texts on larger screens.

plurals
  1. PODetect hard taps anywhere on iPhone through accelerometer
    primarykey
    data
    text
    <p>I am trying to detect the taps which could be anywhere on iPhone not just iPhone screen. Here is a <a href="http://www.knocktounlock.com/public/vid/knock-nojs.mp4" rel="noreferrer">link</a> which shows that it is possible.</p> <p>Basically what i want to do is send an alert if user taps 3 times on iPhone while the Phone is in his pocket. What i have achieved is that i can detect the 3 taps but i also get the false alerts as well in these cases. 1) if user walking, 2) waving his phone 3) running. I need to just check if user has hit his iPhone 3 times.</p> <p>Here is my code.</p> <pre><code>- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { if (handModeOn == NO) { if(pocketFlag == NO) return; } float accelZ = 0.0; float accelX = 0.0; float accelY = 0.0; accelX = (acceleration.x * kFilteringFactor) + (accelX * (1.0 - kFilteringFactor)); accelY = (acceleration.y * kFilteringFactor) + (accelY * (1.0 - kFilteringFactor)); accelZ = (acceleration.z * kFilteringFactor) + (accelZ * (1.0 - kFilteringFactor)); self.z.text = [NSString stringWithFormat:@"%0.1f", -accelZ]; if((-accelZ &gt;= [senstivity floatValue] &amp;&amp; timerFlag) || (-accelZ &lt;= -[senstivity floatValue] &amp;&amp; timerFlag)|| (-accelX &gt;= [senstivity floatValue] &amp;&amp; timerFlag) || (-accelX &lt;= -[senstivity floatValue] &amp;&amp; timerFlag) || (-accelY &gt;= [senstivity floatValue] &amp;&amp; timerFlag) || (-accelY &lt;= -[senstivity floatValue] &amp;&amp; timerFlag)) { timerFlag = false; addValueFlag = true; timer = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(timerTick:) userInfo:nil repeats:YES]; } if(addValueFlag) { if (self.xSwitch.on) { NSLog(@"X sWitch is on"); [self.accArray addObject:[NSNumber numberWithFloat:-accelX]]; } if (self.ySwitch.on) { NSLog(@"Y Switch is on"); [self.accArray addObject:[NSNumber numberWithFloat:-accelY]]; } if (self.zSwitch.on) { NSLog(@"Z Switch is on"); [self.accArray addObject:[NSNumber numberWithFloat:-accelZ]]; } } //} } - (void)timerTick:(NSTimer *)timer1 { [timer1 invalidate]; addValueFlag = false; int count = 0; for(int i = 0; i &lt; self.accArray.count; i++) { if(([[self.accArray objectAtIndex:i] floatValue] &gt;= [senstivity floatValue]) || ([[self.accArray objectAtIndex:i] floatValue] &lt;= -[senstivity floatValue])) { count++; [self playAlarm:@"beep-1" FileType:@"mp3"]; } if(count &gt;= 3) { [self playAlarm:@"06_Alarm___Auto___Rapid_Beeping_1" FileType:@"caf"]; [self showAlert]; timerFlag = true; [self.accArray removeAllObjects]; return; } } [self.accArray removeAllObjects]; timerFlag = true; } </code></pre> <p>Any help will be really appreciated.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload