implement static method

NSURLSessionDelegate implement({
  1. void URLSession_didBecomeInvalidWithError_(
    1. NSURLSession,
    2. NSError?
    )?,
  2. void URLSession_didReceiveChallenge_completionHandler_(
    1. NSURLSession,
    2. NSURLAuthenticationChallenge,
    3. ObjCBlock<Void Function(NSInteger, NSURLCredential?)>
    )?,
  3. void URLSessionDidFinishEventsForBackgroundURLSession_(
    1. NSURLSession
    )?,
  4. bool $keepIsolateAlive = true,
})

Builds an object that implements the NSURLSessionDelegate protocol. To implement multiple protocols, use addToBuilder or objc.ObjCProtocolBuilder directly.

If $keepIsolateAlive is true, this protocol will keep this isolate alive until it is garbage collected by both Dart and ObjC.

Implementation

static NSURLSessionDelegate implement({
  void Function(NSURLSession, objc.NSError?)?
  URLSession_didBecomeInvalidWithError_,
  void Function(
    NSURLSession,
    NSURLAuthenticationChallenge,
    objc.ObjCBlock<ffi.Void Function(NSInteger, NSURLCredential?)>,
  )?
  URLSession_didReceiveChallenge_completionHandler_,
  void Function(NSURLSession)?
  URLSessionDidFinishEventsForBackgroundURLSession_,
  bool $keepIsolateAlive = true,
}) {
  final builder = objc.ObjCProtocolBuilder(debugName: 'NSURLSessionDelegate');
  NSURLSessionDelegate.URLSession_didBecomeInvalidWithError_.implement(
    builder,
    URLSession_didBecomeInvalidWithError_,
  );
  NSURLSessionDelegate
      .URLSession_didReceiveChallenge_completionHandler_.implement(
    builder,
    URLSession_didReceiveChallenge_completionHandler_,
  );
  NSURLSessionDelegate
      .URLSessionDidFinishEventsForBackgroundURLSession_.implement(
    builder,
    URLSessionDidFinishEventsForBackgroundURLSession_,
  );
  builder.addProtocol($protocol);
  return NSURLSessionDelegate.castFrom(
    builder.build(keepIsolateAlive: $keepIsolateAlive),
  );
}