问题描述
在FMX.Platform.iOS
内,此方法已添加到App委托
within FMX.Platform.iOS
this method is added to the App delegate
class_addMethod(appDelegateClass, sel_getUid('application:didReceiveLocalNotification:'),
@applicationDidReceiveLocalNotification, 'v@:@@');
其过程为:
procedure applicationDidReceiveLocalNotification(self: id; _cmd: SEL; application: PUIApplication;
notification: Pointer); cdecl;
begin
PlatformCocoa.FAppDelegate.application(TUIApplication.Wrap(application), TUILocalNotification.Wrap(notification));
end;
我想在我的主机中重载此方法,但是仅当我从FMX.Platform.iOS
I want to overload this method in my main unit, but it only works if I remove the declaration of it from FMX.Platform.iOS
在我的主单元中,按如下所示添加方法:
In my main unit I add the Method as follows:
class_addMethod(objc_getClass('DelphiAppDelegate'), sel_getUid('application:didReceiveLocalNotification:'),
@applicationDidReceiveLocalNotification, 'v@:@@');
我的程序
procedure applicationDidReceiveLocalNotification(self: id; _cmd: SEL;
application: PUIApplication; notification: Pointer);
begin
ShowMessage('it works');
end;
我想尽我所能,尽量不使用FMX.Platform.iOS
源代码,有没有办法告诉编译器使用我的applicationDidReceiveLocalNotification而不是源代码中的那个?
I want to try and Keep out of the FMX.Platform.iOS
source as much as I can, is there a way to tell the compiler to use my applicationDidReceiveLocalNotification and not the one in the source?
推荐答案
由于Embarcadero的方法是使用Objective-C的class_addMethod()
添加的,因此请尝试使用Objective-C的class_replaceMethod()
函数将其替换为您自己的实现.大量的在线教程介绍了如何在iOS中使用方法混淆来添加/覆盖方法.请四处搜寻.不过,您将找不到任何Delphi示例,因此您将不得不进行一些翻译.
Since Embarcadero's method is added using Objective-C's class_addMethod()
, try using Objective-C's class_replaceMethod()
function to replace it with your own implementation. There are tons of online tutorials that explain how to use method swizzling in iOS to add/override methods. Please search around. You will not find any Delphi examples, though, so you will have to do some translating.
这篇关于重载FMX.Platform.iOS中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!