gpt4 book ai didi

ios - 在 FMX.Platform.iOS 中重载方法

转载 作者:行者123 更新时间:2023-11-28 21:35:39 25 4
gpt4 key购买 nike

FMX.Platform.iOS 内此方法被添加到 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 中删除它的声明时才有效。

在我的主要单元中,我添加方法如下:
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 而不是源中的那个?

最佳答案

由于 Embarcadero 的方法是使用 Objective-C 的 class_addMethod() 添加的, 尝试使用 Objective-C 的 class_replaceMethod()函数用您自己的实现替换它。有大量在线教程解释了如何使用 方法调配在 iOS 中添加/覆盖方法。请四处搜寻。但是,您将找不到任何 Delphi 示例,因此您必须进行一些翻译。

关于ios - 在 FMX.Platform.iOS 中重载方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34023980/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com