Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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 钩子接触从使用Delphi XE5的UIView类[Swizzling]内部开始_Ios_Objective C_Delphi_Delphi Xe5_Swizzling - Fatal编程技术网

Ios 钩子接触从使用Delphi XE5的UIView类[Swizzling]内部开始

Ios 钩子接触从使用Delphi XE5的UIView类[Swizzling]内部开始,ios,objective-c,delphi,delphi-xe5,swizzling,Ios,Objective C,Delphi,Delphi Xe5,Swizzling,我正在努力捕捉全球所有的触摸事件。为此,我知道我可以在UIView类中钩住触摸事件过程。我有编译的代码。我的钩子实现是 procedure touchesBeganDetour(self: id; _cmd: SEL; touches: NSSet; withEvent: UIEvent); cdecl; begin Sleep(1); end; 然后我试着用两种不同的方法来钩住它。第一: constructor TTouchEventListener_IOS.Create; var

我正在努力捕捉全球所有的触摸事件。为此,我知道我可以在UIView类中钩住触摸事件过程。我有编译的代码。我的钩子实现是

procedure touchesBeganDetour(self: id; _cmd: SEL; touches: NSSet; withEvent: UIEvent); cdecl;
begin
  Sleep(1);
end;
然后我试着用两种不同的方法来钩住它。第一:

constructor TTouchEventListener_IOS.Create;
var
  FM1, FM2: Pointer
  ViewClass: Pointer;
begin
  inherited;

  ViewClass := objc_getClass('UIView');
  class_addMethod(ViewClass, sel_getUid('touchesBeganDetour:'), @touchesBeganDetour, 'v@:@@');
  FM1 := class_getInstanceMethod(ViewClass, sel_getUid('touchesBegan:withEvent:'));
  FM2 := class_getInstanceMethod(ViewClass, sel_getUid('touchesBeganDetour:'));
  method_exchangeImplementations(FM1, FM2);
end;
这似乎是标准方法。第二个:

constructor TTouchEventListener_IOS.Create;
var
  FM1
  ViewClass: Pointer;
begin
  inherited;

  ViewClass := objc_getClass('UIView');
  FM1 := class_getInstanceMethod(ViewClass, sel_getUid('touchesBegan:withEvent:'));
  method_setImplementation(FM1, @touchesBeganDetour);
end;
据我所知,这也应该有效。我得到了“touchesbreated:withEvent”的实例,所有代码执行时都没有错误。但当我随后触摸模拟器屏幕时,代码在“单元”中的“DispatchToImportSuper”中崩溃。我显然做错了什么,但我不知道是什么。如果这是可行的,那么就可以在不修改Delphi源代码的情况下监听touch事件


有人有什么想法吗?

再次回答我自己的问题。问题在于绕道程序声明。似乎不能指定原始参数,但必须使用指针而不是接口。这可能是由于ObjectVec和object pascal之间的差异造成的。稍后,您将“包装”,从而将指针强制转换为正确的接口

procedure touchesBeganDetour(self: id; _cmd: SEL; touches: Pointer; withEvent: Pointer); cdecl;
begin
  DoNotifyTouchEvent(TNSSet.Wrap(touches), TUIEvent.Wrap(withEvent), teDown);
end;