"Unrecognized Selector Sent to Instance" iOS 本机代码中的错误

"Unrecognized Selector Sent to Instance" error in iOS native code

我在 iPhone 上收到一条我无法理解的 "unrecognized selector sent to instance" 错误消息。我是 运行 来自 XCode 的原生 iOS 来源,当我调用 setInterval() 方法时,我在初始化过程中遇到了这条错误消息。

方法很简单。我正在使用传感器,所以我有这个界面

public interface SensorsNative extends NativeInterface {
  ...
  void setInterval(int type, int delayMicroSeconds);
}

我的 ios 本机实现如下所示:

-(void)setInterval:(int)type delay:(int)delayMicroSeconds {
  // accelerometerUpdateInterval is in seconds.
  NSTimeInterval delaySeconds = delayMicroSeconds / 1000000.0;

  if (type == GYRO) {
    [motionManager setGyroUpdateInterval: delaySeconds];
  } else if (type == ACCEL) {
    [motionManager setAccelerometerUpdateInterval:delaySeconds];
  } else if (type == MAGNET) {
    [motionManager setMagnetometerUpdateInterval: delaySeconds];
  }
}

我的 SensorsNative 实例是静态的,所以它不能被垃圾收集,我可以从附加的 Xcode 输出中看到我的参数有正确的值,我的指针 ptr 是正确的类型。我不明白为什么它不起作用。

您似乎更改了本机实现 iOS 方法的名称。应该是setInterval:param1:,但是你改成了setInterval:delay:

例如


-(void)setInterval:(int)type param1:(int)delayMicroSeconds {
...
}