Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
IOS应用程序无法识别加速计数据或文本输入_Ios_Objective C - Fatal编程技术网

IOS应用程序无法识别加速计数据或文本输入

IOS应用程序无法识别加速计数据或文本输入,ios,objective-c,Ios,Objective C,这个代码没有给我任何输出,甚至没有设置加速计。我首先尝试让设备识别加速计和阈值输入。这是一个简单的加速计应用程序,我可以设置一个thresh hold变量,然后比较以前和当前加速计输出的一些值。thresh输入是一个用于输入的简单文本框。任何帮助都将不胜感激 #import "ViewController.h" @interface ViewController (){ //set up variables for switch and BOOL variables BOOL

这个代码没有给我任何输出,甚至没有设置加速计。我首先尝试让设备识别加速计和阈值输入。这是一个简单的加速计应用程序,我可以设置一个thresh hold变量,然后比较以前和当前加速计输出的一些值。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

显示设置self.motionManager的代码。
如果您实际上没有创建CMMotionManager,那么您正在startSensor:方法中将消息发送给nil,并且您将观察到没有执行加速计回调。

我似乎没有正确设置CMMotionManager。在我看了我的设置之后,它非常直截了当地介绍了如何正确显示所有内容

您是否已连接UI以调用
startSensor
方法?