在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;
但它不起作用!我在传递选项
时做错了什么我声明像
这样的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;
没有工作:(我想念的任何想法?
答案 0 :(得分:1)
我发现它有点疯狂(尝试所有可能和不可能的组合)但我找到了它!
var aImp: procedure(options: nsuinteger); cdecl;
是这样的简单......