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