2017-05-13 47 views
1

在IOS我有这样的功能:Delphi/IOS如何正确使用imp_implementationWithBlock?

- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler __IOS_AVAILABLE(10.0) __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0); 

我的具体问题是这个PARAM:

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; 

,但它没有工作!我的事情我做错事经过选项时

我宣布小鬼功能类似

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; 

没有工作:(任何想法(s)我什么小姐?

回答

1

有点疯狂我怎么找到它(尝试所有可能的和不可能的组合),但我发现它!

var aImp: procedure(options: nsuinteger); cdecl; 

这样是简单的...

+0

这似乎是有悖于苹果的文档:https://developer.apple.com/reference/objectivec/1418587-imp_implementationwithblock?language=objc,但我很高兴你找到答案! –