commit | author | age
|
aca600
|
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 "GULNetworkConstants.h" |
|
20 |
#import "GULNetworkLoggerProtocol.h" |
|
21 |
#import "GULNetworkURLSession.h" |
|
22 |
|
|
23 |
/// Delegate protocol for GULNetwork events. |
|
24 |
@protocol GULNetworkReachabilityDelegate |
|
25 |
|
|
26 |
/// Tells the delegate to handle events when the network reachability changes to connected or not |
|
27 |
/// connected. |
|
28 |
- (void)reachabilityDidChange; |
|
29 |
|
|
30 |
@end |
|
31 |
|
|
32 |
/// The Network component that provides network status and handles network requests and responses. |
|
33 |
/// This is not thread safe. |
|
34 |
/// |
|
35 |
/// NOTE: |
|
36 |
/// User must add FIRAnalytics handleEventsForBackgroundURLSessionID:completionHandler to the |
|
37 |
/// AppDelegate application:handleEventsForBackgroundURLSession:completionHandler: |
|
38 |
@interface GULNetwork : NSObject |
|
39 |
|
|
40 |
/// Indicates if network connectivity is available. |
|
41 |
@property(nonatomic, readonly, getter=isNetworkConnected) BOOL networkConnected; |
|
42 |
|
|
43 |
/// Indicates if there are any uploads in progress. |
|
44 |
@property(nonatomic, readonly, getter=hasUploadInProgress) BOOL uploadInProgress; |
|
45 |
|
|
46 |
/// An optional delegate that can be used in the event when network reachability changes. |
|
47 |
@property(nonatomic, weak) id<GULNetworkReachabilityDelegate> reachabilityDelegate; |
|
48 |
|
|
49 |
/// An optional delegate that can be used to log messages, warnings or errors that occur in the |
|
50 |
/// network operations. |
|
51 |
@property(nonatomic, weak) id<GULNetworkLoggerDelegate> loggerDelegate; |
|
52 |
|
|
53 |
/// Indicates whether the logger should display debug messages. |
|
54 |
@property(nonatomic, assign) BOOL isDebugModeEnabled; |
|
55 |
|
|
56 |
/// The time interval in seconds for the network request to timeout. |
|
57 |
@property(nonatomic, assign) NSTimeInterval timeoutInterval; |
|
58 |
|
|
59 |
/// Initializes with the default reachability host. |
|
60 |
- (instancetype)init; |
|
61 |
|
|
62 |
/// Initializes with a custom reachability host. |
|
63 |
- (instancetype)initWithReachabilityHost:(NSString *)reachabilityHost; |
|
64 |
|
|
65 |
/// Handles events when background session with the given ID has finished. |
|
66 |
+ (void)handleEventsForBackgroundURLSessionID:(NSString *)sessionID |
|
67 |
completionHandler:(GULNetworkSystemCompletionHandler)completionHandler; |
|
68 |
|
|
69 |
/// Compresses and sends a POST request with the provided data to the URL. The session will be |
|
70 |
/// background session if usingBackgroundSession is YES. Otherwise, the POST session is default |
|
71 |
/// session. Returns a session ID or nil if an error occurs. |
|
72 |
- (NSString *)postURL:(NSURL *)url |
|
73 |
payload:(NSData *)payload |
|
74 |
queue:(dispatch_queue_t)queue |
|
75 |
usingBackgroundSession:(BOOL)usingBackgroundSession |
|
76 |
completionHandler:(GULNetworkCompletionHandler)handler; |
|
77 |
|
|
78 |
/// Compresses and sends a POST request with the provided headers and data to the URL. The session |
|
79 |
/// will be background session if usingBackgroundSession is YES. Otherwise, the POST session is |
|
80 |
/// default session. Returns a session ID or nil if an error occurs. |
|
81 |
- (NSString *)postURL:(NSURL *)url |
|
82 |
headers:(NSDictionary *)headers |
|
83 |
payload:(NSData *)payload |
|
84 |
queue:(dispatch_queue_t)queue |
|
85 |
usingBackgroundSession:(BOOL)usingBackgroundSession |
|
86 |
completionHandler:(GULNetworkCompletionHandler)handler; |
|
87 |
|
|
88 |
/// Sends a GET request with the provided data to the URL. The session will be background session |
|
89 |
/// if usingBackgroundSession is YES. Otherwise, the GET session is default session. Returns a |
|
90 |
/// session ID or nil if an error occurs. |
|
91 |
- (NSString *)getURL:(NSURL *)url |
|
92 |
headers:(NSDictionary *)headers |
|
93 |
queue:(dispatch_queue_t)queue |
|
94 |
usingBackgroundSession:(BOOL)usingBackgroundSession |
|
95 |
completionHandler:(GULNetworkCompletionHandler)handler; |
|
96 |
|
|
97 |
@end |