added iOS source code
[wl-app.git] / iOS / Pods / GoogleUtilities / GoogleUtilities / Network / Private / GULNetworkURLSession.h
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
17 #import <Foundation/Foundation.h>
18
19 #import "GULNetworkLoggerProtocol.h"
20
21 typedef void (^GULNetworkCompletionHandler)(NSHTTPURLResponse *response,
22                                             NSData *data,
23                                             NSError *error);
24 typedef void (^GULNetworkURLSessionCompletionHandler)(NSHTTPURLResponse *response,
25                                                       NSData *data,
26                                                       NSString *sessionID,
27                                                       NSError *error);
28 typedef void (^GULNetworkSystemCompletionHandler)(void);
29
30 /// The protocol that uses NSURLSession for iOS >= 7.0 to handle requests and responses.
31 @interface GULNetworkURLSession
32     : NSObject <NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSessionDownloadDelegate>
33
34 /// Indicates whether the background network is enabled. Default value is NO.
35 @property(nonatomic, getter=isBackgroundNetworkEnabled) BOOL backgroundNetworkEnabled;
36
37 /// The logger delegate to log message, errors or warnings that occur during the network operations.
38 @property(nonatomic, weak) id<GULNetworkLoggerDelegate> loggerDelegate;
39
40 /// Calls the system provided completion handler after the background session is finished.
41 + (void)handleEventsForBackgroundURLSessionID:(NSString *)sessionID
42                             completionHandler:(GULNetworkSystemCompletionHandler)completionHandler;
43
44 /// Initializes with logger delegate.
45 - (instancetype)initWithNetworkLoggerDelegate:(id<GULNetworkLoggerDelegate>)networkLoggerDelegate
46     NS_DESIGNATED_INITIALIZER;
47
48 - (instancetype)init NS_UNAVAILABLE;
49
50 /// Sends an asynchronous POST request and calls the provided completion handler when the request
51 /// completes or when errors occur, and returns an ID of the session/connection.
52 - (NSString *)sessionIDFromAsyncPOSTRequest:(NSURLRequest *)request
53                           completionHandler:(GULNetworkURLSessionCompletionHandler)handler;
54
55 /// Sends an asynchronous GET request and calls the provided completion handler when the request
56 /// completes or when errors occur, and returns an ID of the session.
57 - (NSString *)sessionIDFromAsyncGETRequest:(NSURLRequest *)request
58                          completionHandler:(GULNetworkURLSessionCompletionHandler)handler;
59
60 @end