0

このコードは、出力を提供していないか、加速度計をセットアップしているようです。私は何よりもまず、デバイスに加速度計とスレッシュ入力を認識させようとしています。これは単純な加速度計アプリで、しきい値保持変数を設定して、以前と現在の加速度計出力の値を比較できます。thresh 入力は、入力用の単純なテキスト ボックスです。どんな助けでも大歓迎です。

#import "ViewController.h"

@interface ViewController (){
    //set up variables for switch and BOOL variables
    BOOL isStarted;
    BOOL switchX;
    BOOL switchY;
    BOOL switchZ;
}

@end

@implementation ViewController

-(IBAction)startSensor:(id)sender{

    //start with displaying the values...then move onto the just flash method
    //set up the accelerometer function within the button press
    [self.motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
        [self showAccelerationdata:accelerometerData.acceleration];
        //print statements for future debugging.  only in the log files though
        if (error){
            NSLog(@"%@", error);
        }
    }];
}

-(void)viewDidLoad
{
    [super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.
    currentAccelx = 0;
    currentAccely = 0;
    currentAccelz = 0;

    previousAccelx = 0;
    previousAccely = 0;
    previousAccelz = 0;

    //set up class for movement controls
    self.motionManager = [[CMMotionManager alloc] init];
    self.motionManager.accelerometerUpdateInterval = .1;
}

-(IBAction)checkSwitchx:(UISwitch *)sender{
    if (sender.on){
        switchX = TRUE;
    }
    else{
        switchX = FALSE;
    }
}

-(IBAction)checkSwitchy:(UISwitch *)sender{
    if (sender.on){
        switchY = TRUE;
    }
    else{
        switchY = FALSE;
    }
}

-(IBAction)checkSwitchz:(UISwitch *)sender{
    if (sender.on){
        switchZ = TRUE;
    }
    else{
        switchZ = FALSE;
    }
}

-(void)showAccelerationdata:(CMAcceleration)acceleration
{
    self.view.backgroundColor = [UIColor whiteColor];

    if ([thresh.text length] == 0){
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle:@"numbers are blank!" message:@"Please enter numbers!"
                              delegate:self cancelButtonTitle:@"Ok!" otherButtonTitles: nil];
        [alert show];
        [alert resignFirstResponder];
    }
    else{
        threshold = [thresh.text floatValue];
        NSLog(@"%@", thresh);
    }
}

-(void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
4

2 に答える 2

0

self.motionManager を設定したコードを表示します。実際に CMMotionManager を作成しない場合は、startSensor: メソッドで nil にメッセージを送信しているため、加速度計のコールバックが実行されていないことがわかります。

于 2013-10-18T21:09:44.623 に答える
0

CMMotionManager を正しく設定していないようです。セットアップを見た後、すべてを正しく表示する方法は非常に簡単でした。

于 2013-10-29T20:26:11.273 に答える