在 IOS 中我有这个功能:
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler __IOS_AVAILABLE(10.0) __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0);
我的特殊问题是这个参数:
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
我翻译成这样
procedure userNotificationCenterWillPresentNotificationWithCompletionHandler(center: UNUserNotificationCenter;
willPresentNotification: UNNotification;
withCompletionHandler: pointer);
var aImp: procedure(self: pointer; _cmd: pointer; const options); cdecl;
aOptions: UNNotificationPresentationOptions;
begin
@aImp := imp_implementationWithBlock(withCompletionHandler);
aOptions := UNNotificationPresentationOptionAlert;
aImp(self, nil, aOptions);
imp_removeBlock(@aImp);
end;
但是不行!我想我在通过 options
时做错了我像这样声明 imp 函数
var aImp: procedure(self: pointer; _cmd: pointer; const options); cdecl;
aOptions := UNNotificationPresentationOptionAlert;
但也许不是好方法,我试着声明它
var aImp: procedure(self: pointer; _cmd: pointer; options: pointer); cdecl;
aOptions := pointer(UNNotificationPresentationOptionAlert);
或者喜欢
var aImp: procedure(self: pointer; _cmd: pointer; options: nsuinteger); cdecl;
aOptions := UNNotificationPresentationOptionAlert;
没有用 :( 我想念什么?
最佳答案
有点疯狂我是如何找到它的(尝试所有可能和不可能的组合)但我找到了!
var aImp: procedure(options: nsuinteger); cdecl;
是的,就这么简单......
关于ios - Delphi/IOS 如何正确使用imp_implementationWithBlock?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43958633/