Код: Выделить всё
- (void)URLSession:(NSURLSession *)session
task:(NSURLSessionTask *)task willBeginDelayedRequest:(NSURLRequest *)request completionHandler:(void (NS_SWIFT_SENDABLE ^)(NSURLSessionDelayedRequestDisposition disposition,
NSURLRequest * _Nullable newRequest))completionHandler API_AVAILABLE(macos(10.13), ios(11.0), watchos(4.0), tvos(11.0));
Код: Выделить всё
procedure TURLSessionDelegate.URLSession(session: NSURLSession;
task: NSURLSessionTask;
willBeginDelayedRequest: NSURLRequest;
completionHandler: Pointer);
var
LCompletionHandlerBlock: procedure(disposition: NSURLSessionDelayedRequestDisposition;
newRequest: NSURLRequest); cdecl;
begin
@LCompletionHandlerBlock := imp_implementationWithBlock(completionHandler);
try
LCompletionHandlerBlock(NSURLSessionDelayedRequestCancel, nil);
finally
imp_removeBlock(@LCompletionHandlerBlock);
end;
end;
Код: Выделить всё
LCompletionHandlerBlock(NSURLSessionDelayedRequestCancel, nil);
Код: Выделить всё
procedure TALHttpWorker.TURLSessionDelegate.URLSession(session: NSURLSession;
task: NSURLSessionTask;
willBeginDelayedRequest: NSURLRequest;
completionHandler: Pointer);
var
LCompletionHandlerBlock: procedure(disposition: NSURLSessionDelayedRequestDisposition;
zzz: Pointer;
newRequest: Pointer;
www: Pointer); cdecl;
begin
@LCompletionHandlerBlock := imp_implementationWithBlock(completionHandler);
try
LCompletionHandlerBlock(NSURLSessionDelayedRequestUseNewRequest,
nil,
NSObjectToID(willBeginDelayedRequest),
nil);
finally
imp_removeBlock(@LCompletionHandlerBlock);
end;
end;
Если я объявлю это как процедуру (disposition: NSURLSessionDelayedRequestDisposition; zzz: Pointer; newRequest: Pointer; www: Pointer); cdecl; и передать фиктивные нулевые значения для zzz и www → это работает, и disposition/newRequest правильно учитываются.
Я не понимаю, зачем мне нужны эти два дополнительных фиктивных параметра, чтобы все работало.
Исходная сигнатура блока Objective-C имеет только два параметра:
Код: Выделить всё
void (^)(NSURLSessionDelayedRequestDisposition disposition,
NSURLRequest * _Nullable newRequest)
- Почему происходит сбой «естественного» перевода Delphi только с двумя параметрами?
- Почему добавление двух дополнительных параметров указателя (zzz / www) внезапно заставляет его работать?
- Каково правильное объявление Delphi для этого блока завершенияHandler при использовании imp_implementationWithBlock?
Подробнее здесь: https://stackoverflow.com/questions/798 ... ut-crashin
Мобильная версия