commit | author | age
|
bad748
|
1 |
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved. |
W |
2 |
// |
|
3 |
// You are hereby granted a non-exclusive, worldwide, royalty-free license to use, |
|
4 |
// copy, modify, and distribute this software in source code or binary form for use |
|
5 |
// in connection with the web services and APIs provided by Facebook. |
|
6 |
// |
|
7 |
// As with any software that integrates with the Facebook platform, your use of |
|
8 |
// this software is subject to the Facebook Developer Principles and Policies |
|
9 |
// [http://developers.facebook.com/policy/]. This copyright notice shall be |
|
10 |
// included in all copies or substantial portions of the software. |
|
11 |
// |
|
12 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
13 |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
|
14 |
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
|
15 |
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
|
16 |
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
|
17 |
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
18 |
|
|
19 |
#import <Foundation/Foundation.h> |
|
20 |
|
e81c27
|
21 |
NS_ASSUME_NONNULL_BEGIN |
H |
22 |
|
|
23 |
/** |
|
24 |
The key in the result dictionary for requests to old versions of the Graph API |
|
25 |
whose response is not a JSON object. |
|
26 |
|
|
27 |
|
|
28 |
When a request returns a non-JSON response (such as a "true" literal), that response |
|
29 |
will be wrapped into a dictionary using this const as the key. This only applies for very few Graph API |
|
30 |
prior to v2.1. |
|
31 |
*/ |
|
32 |
FOUNDATION_EXPORT NSString *const FBSDKNonJSONResponseProperty |
|
33 |
NS_SWIFT_NAME(NonJSONResponseProperty); |
|
34 |
|
bad748
|
35 |
@class FBSDKGraphRequest; |
W |
36 |
@class FBSDKGraphRequestConnection; |
|
37 |
|
9febd9
|
38 |
/** |
e81c27
|
39 |
FBSDKGraphRequestBlock |
bad748
|
40 |
|
9febd9
|
41 |
A block that is passed to addRequest to register for a callback with the results of that |
bad748
|
42 |
request once the connection completes. |
W |
43 |
|
|
44 |
Pass a block of this type when calling addRequest. This will be called once |
|
45 |
the request completes. The call occurs on the UI thread. |
|
46 |
|
e81c27
|
47 |
@param connection The `FBSDKGraphRequestConnection` that sent the request. |
bad748
|
48 |
|
e81c27
|
49 |
@param result The result of the request. This is a translation of |
bad748
|
50 |
JSON data to `NSDictionary` and `NSArray` objects. This |
W |
51 |
is nil if there was an error. |
|
52 |
|
e81c27
|
53 |
@param error The `NSError` representing any error that occurred. |
bad748
|
54 |
|
W |
55 |
*/ |
e81c27
|
56 |
typedef void (^FBSDKGraphRequestBlock)(FBSDKGraphRequestConnection *_Nullable connection, |
H |
57 |
id _Nullable result, |
|
58 |
NSError *_Nullable error) |
|
59 |
NS_SWIFT_NAME(GraphRequestBlock); |
bad748
|
60 |
|
9febd9
|
61 |
/** |
bad748
|
62 |
@protocol |
W |
63 |
|
9febd9
|
64 |
The `FBSDKGraphRequestConnectionDelegate` protocol defines the methods used to receive network |
bad748
|
65 |
activity progress information from a <FBSDKGraphRequestConnection>. |
W |
66 |
*/ |
e81c27
|
67 |
NS_SWIFT_NAME(GraphRequestConnectionDelegate) |
bad748
|
68 |
@protocol FBSDKGraphRequestConnectionDelegate <NSObject> |
W |
69 |
|
|
70 |
@optional |
|
71 |
|
9febd9
|
72 |
/** |
bad748
|
73 |
@method |
W |
74 |
|
9febd9
|
75 |
Tells the delegate the request connection will begin loading |
bad748
|
76 |
|
9febd9
|
77 |
|
W |
78 |
|
bad748
|
79 |
If the <FBSDKGraphRequestConnection> is created using one of the convenience factory methods prefixed with |
W |
80 |
start, the object returned from the convenience method has already begun loading and this method |
|
81 |
will not be called when the delegate is set. |
|
82 |
|
13e53a
|
83 |
@param connection The request connection that is starting a network request |
bad748
|
84 |
*/ |
W |
85 |
- (void)requestConnectionWillBeginLoading:(FBSDKGraphRequestConnection *)connection; |
|
86 |
|
9febd9
|
87 |
/** |
bad748
|
88 |
@method |
W |
89 |
|
9febd9
|
90 |
Tells the delegate the request connection finished loading |
bad748
|
91 |
|
9febd9
|
92 |
|
W |
93 |
|
|
94 |
If the request connection completes without a network error occurring then this method is called. |
bad748
|
95 |
Invocation of this method does not indicate success of every <FBSDKGraphRequest> made, only that the |
e81c27
|
96 |
request connection has no further activity. Use the error argument passed to the FBSDKGraphRequestBlock |
bad748
|
97 |
block to determine success or failure of each <FBSDKGraphRequest>. |
W |
98 |
|
|
99 |
This method is invoked after the completion handler for each <FBSDKGraphRequest>. |
|
100 |
|
13e53a
|
101 |
@param connection The request connection that successfully completed a network request |
bad748
|
102 |
*/ |
W |
103 |
- (void)requestConnectionDidFinishLoading:(FBSDKGraphRequestConnection *)connection; |
|
104 |
|
9febd9
|
105 |
/** |
bad748
|
106 |
@method |
W |
107 |
|
9febd9
|
108 |
Tells the delegate the request connection failed with an error |
bad748
|
109 |
|
9febd9
|
110 |
|
W |
111 |
|
bad748
|
112 |
If the request connection fails with a network error then this method is called. The `error` |
W |
113 |
argument specifies why the network connection failed. The `NSError` object passed to the |
e81c27
|
114 |
FBSDKGraphRequestBlock block may contain additional information. |
bad748
|
115 |
|
13e53a
|
116 |
@param connection The request connection that successfully completed a network request |
H |
117 |
@param error The `NSError` representing the network error that occurred, if any. May be nil |
bad748
|
118 |
in some circumstances. Consult the `NSError` for the <FBSDKGraphRequest> for reliable |
W |
119 |
failure information. |
|
120 |
*/ |
|
121 |
- (void)requestConnection:(FBSDKGraphRequestConnection *)connection |
|
122 |
didFailWithError:(NSError *)error; |
|
123 |
|
9febd9
|
124 |
/** |
bad748
|
125 |
@method |
W |
126 |
|
9febd9
|
127 |
Tells the delegate how much data has been sent and is planned to send to the remote host |
bad748
|
128 |
|
9febd9
|
129 |
|
W |
130 |
|
bad748
|
131 |
The byte count arguments refer to the aggregated <FBSDKGraphRequest> objects, not a particular <FBSDKGraphRequest>. |
W |
132 |
|
13e53a
|
133 |
Like `NSURLSession`, the values may change in unexpected ways if data needs to be resent. |
bad748
|
134 |
|
13e53a
|
135 |
@param connection The request connection transmitting data to a remote host |
H |
136 |
@param bytesWritten The number of bytes sent in the last transmission |
|
137 |
@param totalBytesWritten The total number of bytes sent to the remote host |
|
138 |
@param totalBytesExpectedToWrite The total number of bytes expected to send to the remote host |
bad748
|
139 |
*/ |
W |
140 |
- (void)requestConnection:(FBSDKGraphRequestConnection *)connection |
|
141 |
didSendBodyData:(NSInteger)bytesWritten |
|
142 |
totalBytesWritten:(NSInteger)totalBytesWritten |
|
143 |
totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite; |
|
144 |
|
|
145 |
@end |
|
146 |
|
9febd9
|
147 |
/** |
bad748
|
148 |
|
9febd9
|
149 |
The `FBSDKGraphRequestConnection` represents a single connection to Facebook to service a request. |
bad748
|
150 |
|
9febd9
|
151 |
|
W |
152 |
|
bad748
|
153 |
The request settings are encapsulated in a reusable <FBSDKGraphRequest> object. The |
W |
154 |
`FBSDKGraphRequestConnection` object encapsulates the concerns of a single communication |
|
155 |
e.g. starting a connection, canceling a connection, or batching requests. |
|
156 |
|
|
157 |
*/ |
e81c27
|
158 |
NS_SWIFT_NAME(GraphRequestConnection) |
bad748
|
159 |
@interface FBSDKGraphRequestConnection : NSObject |
e81c27
|
160 |
|
H |
161 |
/** |
|
162 |
The default timeout on all FBSDKGraphRequestConnection instances. Defaults to 60 seconds. |
|
163 |
*/ |
|
164 |
@property (class, nonatomic, assign) NSTimeInterval defaultConnectionTimeout; |
bad748
|
165 |
|
9febd9
|
166 |
/** |
W |
167 |
The delegate object that receives updates. |
bad748
|
168 |
*/ |
e81c27
|
169 |
@property (nonatomic, weak, nullable) id<FBSDKGraphRequestConnectionDelegate> delegate; |
bad748
|
170 |
|
9febd9
|
171 |
/** |
W |
172 |
Gets or sets the timeout interval to wait for a response before giving up. |
bad748
|
173 |
*/ |
13e53a
|
174 |
@property (nonatomic, assign) NSTimeInterval timeout; |
bad748
|
175 |
|
9febd9
|
176 |
/** |
W |
177 |
The raw response that was returned from the server. (readonly) |
bad748
|
178 |
|
9febd9
|
179 |
|
W |
180 |
|
bad748
|
181 |
This property can be used to inspect HTTP headers that were returned from |
W |
182 |
the server. |
|
183 |
|
|
184 |
The property is nil until the request completes. If there was a response |
e81c27
|
185 |
then this property will be non-nil during the FBSDKGraphRequestBlock callback. |
bad748
|
186 |
*/ |
49b883
|
187 |
@property (nonatomic, retain, readonly, nullable) NSHTTPURLResponse *urlResponse; |
e81c27
|
188 |
|
H |
189 |
/** |
|
190 |
Determines the operation queue that is used to call methods on the connection's delegate. |
|
191 |
|
|
192 |
By default, a connection is scheduled on the current thread in the default mode when it is created. |
|
193 |
You cannot reschedule a connection after it has started. |
|
194 |
*/ |
|
195 |
@property (nonatomic, retain) NSOperationQueue *delegateQueue; |
bad748
|
196 |
|
9febd9
|
197 |
/** |
bad748
|
198 |
@methodgroup Class methods |
W |
199 |
*/ |
|
200 |
|
9febd9
|
201 |
/** |
bad748
|
202 |
@methodgroup Adding requests |
W |
203 |
*/ |
|
204 |
|
9febd9
|
205 |
/** |
bad748
|
206 |
@method |
W |
207 |
|
9febd9
|
208 |
This method adds an <FBSDKGraphRequest> object to this connection. |
bad748
|
209 |
|
13e53a
|
210 |
@param request A request to be included in the round-trip when start is called. |
H |
211 |
@param handler A handler to call back when the round-trip completes or times out. |
bad748
|
212 |
|
W |
213 |
The completion handler is retained until the block is called upon the |
|
214 |
completion or cancellation of the connection. |
|
215 |
*/ |
|
216 |
- (void)addRequest:(FBSDKGraphRequest *)request |
e81c27
|
217 |
completionHandler:(FBSDKGraphRequestBlock)handler; |
bad748
|
218 |
|
9febd9
|
219 |
/** |
bad748
|
220 |
@method |
W |
221 |
|
9febd9
|
222 |
This method adds an <FBSDKGraphRequest> object to this connection. |
bad748
|
223 |
|
13e53a
|
224 |
@param request A request to be included in the round-trip when start is called. |
bad748
|
225 |
|
13e53a
|
226 |
@param handler A handler to call back when the round-trip completes or times out. |
bad748
|
227 |
The handler will be invoked on the main thread. |
W |
228 |
|
e81c27
|
229 |
@param name A name for this request. This can be used to feed |
bad748
|
230 |
the results of one request to the input of another <FBSDKGraphRequest> in the same |
W |
231 |
`FBSDKGraphRequestConnection` as described in |
|
232 |
[Graph API Batch Requests]( https://developers.facebook.com/docs/reference/api/batch/ ). |
9febd9
|
233 |
|
bad748
|
234 |
The completion handler is retained until the block is called upon the |
W |
235 |
completion or cancellation of the connection. This request can be named |
|
236 |
to allow for using the request's response in a subsequent request. |
|
237 |
*/ |
|
238 |
- (void)addRequest:(FBSDKGraphRequest *)request |
13e53a
|
239 |
batchEntryName:(NSString *)name |
e81c27
|
240 |
completionHandler:(FBSDKGraphRequestBlock)handler; |
bad748
|
241 |
|
9febd9
|
242 |
/** |
bad748
|
243 |
@method |
W |
244 |
|
9febd9
|
245 |
This method adds an <FBSDKGraphRequest> object to this connection. |
bad748
|
246 |
|
13e53a
|
247 |
@param request A request to be included in the round-trip when start is called. |
bad748
|
248 |
|
13e53a
|
249 |
@param handler A handler to call back when the round-trip completes or times out. |
bad748
|
250 |
|
e81c27
|
251 |
@param batchParameters The dictionary of parameters to include for this request |
bad748
|
252 |
as described in [Graph API Batch Requests]( https://developers.facebook.com/docs/reference/api/batch/ ). |
W |
253 |
Examples include "depends_on", "name", or "omit_response_on_success". |
9febd9
|
254 |
|
bad748
|
255 |
The completion handler is retained until the block is called upon the |
W |
256 |
completion or cancellation of the connection. This request can be named |
|
257 |
to allow for using the request's response in a subsequent request. |
|
258 |
*/ |
|
259 |
- (void)addRequest:(FBSDKGraphRequest *)request |
49b883
|
260 |
batchParameters:(nullable NSDictionary<NSString *, id> *)batchParameters |
e81c27
|
261 |
completionHandler:(FBSDKGraphRequestBlock)handler; |
bad748
|
262 |
|
9febd9
|
263 |
/** |
bad748
|
264 |
@methodgroup Instance methods |
W |
265 |
*/ |
|
266 |
|
9febd9
|
267 |
/** |
bad748
|
268 |
@method |
W |
269 |
|
9febd9
|
270 |
Signals that a connection should be logically terminated as the |
bad748
|
271 |
application is no longer interested in a response. |
9febd9
|
272 |
|
bad748
|
273 |
Synchronously calls any handlers indicating the request was cancelled. Cancel |
W |
274 |
does not guarantee that the request-related processing will cease. It |
|
275 |
does promise that all handlers will complete before the cancel returns. A call to |
|
276 |
cancel prior to a start implies a cancellation of all requests associated |
|
277 |
with the connection. |
|
278 |
*/ |
|
279 |
- (void)cancel; |
|
280 |
|
9febd9
|
281 |
/** |
bad748
|
282 |
@method |
W |
283 |
|
9febd9
|
284 |
This method starts a connection with the server and is capable of handling all of the |
bad748
|
285 |
requests that were added to the connection. |
W |
286 |
|
9febd9
|
287 |
|
W |
288 |
By default, a connection is scheduled on the current thread in the default mode when it is created. |
bad748
|
289 |
See `setDelegateQueue:` for other options. |
W |
290 |
|
|
291 |
This method cannot be called twice for an `FBSDKGraphRequestConnection` instance. |
|
292 |
*/ |
|
293 |
- (void)start; |
|
294 |
|
9febd9
|
295 |
/** |
bad748
|
296 |
@method |
W |
297 |
|
9febd9
|
298 |
Overrides the default version for a batch request |
W |
299 |
|
bad748
|
300 |
The SDK automatically prepends a version part, such as "v2.0" to API paths in order to simplify API versioning |
W |
301 |
for applications. If you want to override the version part while using batch requests on the connection, call |
|
302 |
this method to set the version for the batch request. |
|
303 |
|
13e53a
|
304 |
@param version This is a string in the form @"v2.0" which will be used for the version part of an API path |
bad748
|
305 |
*/ |
13e53a
|
306 |
- (void)overrideGraphAPIVersion:(NSString *)version; |
H |
307 |
|
bad748
|
308 |
@end |
W |
309 |
|
e81c27
|
310 |
NS_ASSUME_NONNULL_END |