FIRNetworkURLSession.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. #import "FIRNetworkLoggerProtocol.h"
  18. typedef void (^FIRNetworkCompletionHandler)(NSHTTPURLResponse *response,
  19. NSData *data,
  20. NSError *error);
  21. typedef void (^FIRNetworkURLSessionCompletionHandler)(NSHTTPURLResponse *response,
  22. NSData *data,
  23. NSString *sessionID,
  24. NSError *error);
  25. typedef void (^FIRNetworkSystemCompletionHandler)(void);
  26. /// The protocol that uses NSURLSession for iOS >= 7.0 to handle requests and responses.
  27. @interface FIRNetworkURLSession
  28. : NSObject <NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSessionDownloadDelegate>
  29. /// Indicates whether the background network is enabled. Default value is NO.
  30. @property(nonatomic, getter=isBackgroundNetworkEnabled) BOOL backgroundNetworkEnabled;
  31. /// The logger delegate to log message, errors or warnings that occur during the network operations.
  32. @property(nonatomic, weak) id<FIRNetworkLoggerDelegate> loggerDelegate;
  33. /// Calls the system provided completion handler after the background session is finished.
  34. + (void)handleEventsForBackgroundURLSessionID:(NSString *)sessionID
  35. completionHandler:(FIRNetworkSystemCompletionHandler)completionHandler;
  36. /// Initializes with logger delegate.
  37. - (instancetype)initWithNetworkLoggerDelegate:(id<FIRNetworkLoggerDelegate>)networkLoggerDelegate
  38. NS_DESIGNATED_INITIALIZER;
  39. - (instancetype)init NS_UNAVAILABLE;
  40. /// Sends an asynchronous POST request and calls the provided completion handler when the request
  41. /// completes or when errors occur, and returns an ID of the session/connection.
  42. - (NSString *)sessionIDFromAsyncPOSTRequest:(NSURLRequest *)request
  43. completionHandler:(FIRNetworkURLSessionCompletionHandler)handler;
  44. /// Sends an asynchronous GET request and calls the provided completion handler when the request
  45. /// completes or when errors occur, and returns an ID of the session.
  46. - (NSString *)sessionIDFromAsyncGETRequest:(NSURLRequest *)request
  47. completionHandler:(FIRNetworkURLSessionCompletionHandler)handler;
  48. @end