/
FBSDKInternalUtility.h
366 lines (313 loc) · 14.2 KB
/
FBSDKInternalUtility.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
//
// You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
// copy, modify, and distribute this software in source code or binary form for use
// in connection with the web services and APIs provided by Facebook.
//
// As with any software that integrates with the Facebook platform, your use of
// this software is subject to the Facebook Developer Principles and Policies
// [http://developers.facebook.com/policy/]. This copyright notice shall be
// included in all copies or substantial portions of the software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#define FBSDK_CANOPENURL_FACEBOOK @"fbauth2"
#define FBSDK_CANOPENURL_FBAPI @"fbapi"
#define FBSDK_CANOPENURL_MESSENGER @"fb-messenger-api"
#define FBSDK_CANOPENURL_MSQRD_PLAYER @"msqrdplayer"
#define FBSDK_CANOPENURL_SHARE_EXTENSION @"fbshareextension"
typedef NS_ENUM(int32_t, FBSDKUIKitVersion)
{
FBSDKUIKitVersion_6_0 = 0x0944,
FBSDKUIKitVersion_6_1 = 0x094C,
FBSDKUIKitVersion_7_0 = 0x0B57,
FBSDKUIKitVersion_7_1 = 0x0B77,
FBSDKUIKitVersion_8_0 = 0x0CF6,
};
@interface FBSDKInternalUtility : NSObject
/**
Constructs the scheme for apps that come to the current app through the bridge.
*/
+ (NSString *)appURLScheme;
/**
Constructs an URL for the current app.
- Parameter host: The host for the URL.
- Parameter path: The path for the URL.
- Parameter queryParameters: The query parameters for the URL. This will be converted into a query string.
- Parameter errorRef: If an error occurs, upon return contains an NSError object that describes the problem.
- Returns: The app URL.
*/
+ (NSURL *)appURLWithHost:(NSString *)host
path:(NSString *)path
queryParameters:(NSDictionary *)queryParameters
error:(NSError *__autoreleasing *)errorRef;
/**
Parses an FB url's query params (and potentially fragment) into a dictionary.
- Parameter url: The FB url.
- Returns: A dictionary with the key/value pairs.
*/
+ (NSDictionary *)dictionaryFromFBURL:(NSURL *)url;
/**
Adds an object to an array if it is not nil.
- Parameter array: The array to add the object to.
- Parameter object: The object to add to the array.
*/
+ (void)array:(NSMutableArray *)array addObject:(id)object;
/**
Returns bundle for returning localized strings
We assume a convention of a bundle named FBSDKStrings.bundle, otherwise we
return the main bundle.
*/
+ (NSBundle *)bundleForStrings;
/**
Converts simple value types to the string equivalent for serializing to a request query or body.
- Parameter value: The value to be converted.
- Returns: The value that may have been converted if able (otherwise the input param).
*/
+ (id)convertRequestValue:(id)value;
/**
Gets the milliseconds since the Unix Epoch.
Changes in the system clock will affect this value.
- Returns: The number of milliseconds since the Unix Epoch.
*/
+ (unsigned long)currentTimeInMilliseconds;
/**
Sets an object for a key in a dictionary if it is not nil.
- Parameter dictionary: The dictionary to set the value for.
- Parameter object: The value to set after serializing to JSON.
- Parameter key: The key to set the value for.
- Parameter errorRef: If an error occurs, upon return contains an NSError object that describes the problem.
- Returns: NO if an error occurred while serializing the object, otherwise YES.
*/
+ (BOOL)dictionary:(NSMutableDictionary *)dictionary
setJSONStringForObject:(id)object
forKey:(id<NSCopying>)key
error:(NSError *__autoreleasing *)errorRef;
/**
Sets an object for a key in a dictionary if it is not nil.
- Parameter dictionary: The dictionary to set the value for.
- Parameter object: The value to set.
- Parameter key: The key to set the value for.
*/
+ (void)dictionary:(NSMutableDictionary *)dictionary setObject:(id)object forKey:(id<NSCopying>)key;
/**
Constructs a Facebook URL.
- Parameter hostPrefix: The prefix for the host, such as 'm', 'graph', etc.
- Parameter path: The path for the URL. This may or may not include a version.
- Parameter queryParameters: The query parameters for the URL. This will be converted into a query string.
- Parameter errorRef: If an error occurs, upon return contains an NSError object that describes the problem.
- Returns: The Facebook URL.
*/
+ (NSURL *)facebookURLWithHostPrefix:(NSString *)hostPrefix
path:(NSString *)path
queryParameters:(NSDictionary *)queryParameters
error:(NSError *__autoreleasing *)errorRef;
/**
Constructs a Facebook URL.
- Parameter hostPrefix: The prefix for the host, such as 'm', 'graph', etc.
- Parameter path: The path for the URL. This may or may not include a version.
- Parameter queryParameters: The query parameters for the URL. This will be converted into a query string.
- Parameter defaultVersion: A version to add to the URL if none is found in the path.
- Parameter errorRef: If an error occurs, upon return contains an NSError object that describes the problem.
- Returns: The Facebook URL.
*/
+ (NSURL *)facebookURLWithHostPrefix:(NSString *)hostPrefix
path:(NSString *)path
queryParameters:(NSDictionary *)queryParameters
defaultVersion:(NSString *)defaultVersion
error:(NSError *__autoreleasing *)errorRef;
/**
Tests whether the supplied URL is a valid URL for opening in the browser.
- Parameter URL: The URL to test.
- Returns: YES if the URL refers to an http or https resource, otherwise NO.
*/
+ (BOOL)isBrowserURL:(NSURL *)URL;
/**
Tests whether the supplied bundle identifier references a Facebook app.
- Parameter bundleIdentifier: The bundle identifier to test.
- Returns: YES if the bundle identifier refers to a Facebook app, otherwise NO.
*/
+ (BOOL)isFacebookBundleIdentifier:(NSString *)bundleIdentifier;
/**
Tests whether the operating system is at least the specified version.
- Parameter version: The version to test against.
- Returns: YES if the operating system is greater than or equal to the specified version, otherwise NO.
*/
+ (BOOL)isOSRunTimeVersionAtLeast:(NSOperatingSystemVersion)version;
/**
Tests whether the supplied bundle identifier references the Safari app.
- Parameter bundleIdentifier: The bundle identifier to test.
- Returns: YES if the bundle identifier refers to the Safari app, otherwise NO.
*/
+ (BOOL)isSafariBundleIdentifier:(NSString *)bundleIdentifier;
/**
Tests whether the UIKit version that the current app was linked to is at least the specified version.
- Parameter version: The version to test against.
- Returns: YES if the linked UIKit version is greater than or equal to the specified version, otherwise NO.
*/
+ (BOOL)isUIKitLinkTimeVersionAtLeast:(FBSDKUIKitVersion)version;
/**
Tests whether the UIKit version in the runtime is at least the specified version.
- Parameter version: The version to test against.
- Returns: YES if the runtime UIKit version is greater than or equal to the specified version, otherwise NO.
*/
+ (BOOL)isUIKitRunTimeVersionAtLeast:(FBSDKUIKitVersion)version;
/**
Converts an object into a JSON string.
- Parameter object: The object to convert to JSON.
- Parameter errorRef: If an error occurs, upon return contains an NSError object that describes the problem.
- Parameter invalidObjectHandler: Handles objects that are invalid, returning a replacement value or nil to ignore.
- Returns: A JSON string or nil if the object cannot be converted to JSON.
*/
+ (NSString *)JSONStringForObject:(id)object
error:(NSError *__autoreleasing *)errorRef
invalidObjectHandler:(id(^)(id object, BOOL *stop))invalidObjectHandler;
/**
Checks equality between 2 objects.
Checks for pointer equality, nils, isEqual:.
- Parameter object: The first object to compare.
- Parameter other: The second object to compare.
- Returns: YES if the objects are equal, otherwise NO.
*/
+ (BOOL)object:(id)object isEqualToObject:(id)other;
/**
Converts a JSON string into an object
- Parameter string: The JSON string to convert.
- Parameter errorRef: If an error occurs, upon return contains an NSError object that describes the problem.
- Returns: An NSDictionary, NSArray, NSString or NSNumber containing the object representation, or nil if the string
cannot be converted.
*/
+ (id)objectForJSONString:(NSString *)string error:(NSError *__autoreleasing *)errorRef;
/**
The version of the operating system on which the process is executing.
*/
+ (NSOperatingSystemVersion)operatingSystemVersion;
/**
Constructs a query string from a dictionary.
- Parameter dictionary: The dictionary with key/value pairs for the query string.
- Parameter errorRef: If an error occurs, upon return contains an NSError object that describes the problem.
- Parameter invalidObjectHandler: Handles objects that are invalid, returning a replacement value or nil to ignore.
- Returns: Query string representation of the parameters.
*/
+ (NSString *)queryStringWithDictionary:(NSDictionary *)dictionary
error:(NSError *__autoreleasing *)errorRef
invalidObjectHandler:(id(^)(id object, BOOL *stop))invalidObjectHandler;
/**
Tests whether the orientation should be manually adjusted for views outside of the root view controller.
With the legacy layout the developer must worry about device orientation when working with views outside of
the window's root view controller and apply the correct rotation transform and/or swap a view's width and height
values. If the application was linked with UIKit on iOS 7 or earlier or the application is running on iOS 7 or earlier
then we need to use the legacy layout code. Otherwise if the application was linked with UIKit on iOS 8 or later and
the application is running on iOS 8 or later, UIKit handles all of the rotation complexity and the origin is always in
the top-left and no rotation transform is necessary.
- Returns: YES if if the orientation must be manually adjusted, otherwise NO.
*/
+ (BOOL)shouldManuallyAdjustOrientation;
/**
Constructs an NSURL.
- Parameter scheme: The scheme for the URL.
- Parameter host: The host for the URL.
- Parameter path: The path for the URL.
- Parameter queryParameters: The query parameters for the URL. This will be converted into a query string.
- Parameter errorRef: If an error occurs, upon return contains an NSError object that describes the problem.
- Returns: The URL.
*/
+ (NSURL *)URLWithScheme:(NSString *)scheme
host:(NSString *)host
path:(NSString *)path
queryParameters:(NSDictionary *)queryParameters
error:(NSError *__autoreleasing *)errorRef;
/**
* Deletes all the cookies in the NSHTTPCookieStorage for Facebook web dialogs
*/
+ (void)deleteFacebookCookies;
/**
Extracts permissions from a response fetched from me/permissions
- Parameter responseObject: the response
- Parameter grantedPermissions: the set to add granted permissions to
- Parameter declinedPermissions: the set to add declined permissions to.
*/
+ (void)extractPermissionsFromResponse:(NSDictionary *)responseObject
grantedPermissions:(NSMutableSet *)grantedPermissions
declinedPermissions:(NSMutableSet *)declinedPermissions;
/**
Registers a transient object so that it will not be deallocated until unregistered
- Parameter object: The transient object
*/
+ (void)registerTransientObject:(id)object;
/**
Unregisters a transient object that was previously registered with registerTransientObject:
- Parameter object: The transient object
*/
+ (void)unregisterTransientObject:(__weak id)object;
/**
validates that the app ID is non-nil, throws an NSException if nil.
*/
+ (void)validateAppID;
/**
Validates that the client access token is non-nil, otherwise - throws an NSException otherwise.
Returns the composed client access token.
*/
+ (NSString *)validateRequiredClientAccessToken;
/**
validates that the right URL schemes are registered, throws an NSException if not.
*/
+ (void)validateURLSchemes;
/**
validates that Facebook reserved URL schemes are not registered, throws an NSException if they are.
*/
+ (void)validateFacebookReservedURLSchemes;
/**
Attempts to find the first UIViewController in the view's responder chain. Returns nil if not found.
*/
+ (UIViewController *)viewControllerForView:(UIView *)view;
/**
returns true if the url scheme is registered in the CFBundleURLTypes
*/
+ (BOOL)isRegisteredURLScheme:(NSString *)urlScheme;
/**
returns the current key window
*/
+ (UIWindow *)findWindow;
/**
returns currently displayed top view controller.
*/
+ (UIViewController *)topMostViewController;
/**
Converts NSData to a hexadecimal UTF8 String.
*/
+ (NSString *)hexadecimalStringFromData:(NSData *)data;
/*
Checks if the permission is a publish permission.
*/
+ (BOOL)isPublishPermission:(NSString *)permission;
/*
Checks if the set of permissions are all read permissions.
*/
+ (BOOL)areAllPermissionsReadPermissions:(NSSet *)permissions;
/*
Checks if the set of permissions are all publish permissions.
*/
+ (BOOL)areAllPermissionsPublishPermissions:(NSSet *)permissions;
#pragma mark - FB Apps Installed
+ (BOOL)isFacebookAppInstalled;
+ (BOOL)isMessengerAppInstalled;
+ (BOOL)isMSQRDPlayerAppInstalled;
+ (void)checkRegisteredCanOpenURLScheme:(NSString *)urlScheme;
+ (BOOL)isRegisteredCanOpenURLScheme:(NSString *)urlScheme;
#define FBSDKConditionalLog(condition, loggingBehavior, desc, ...) \
{ \
if (!(condition)) { \
NSString *msg = [NSString stringWithFormat:(desc), ##__VA_ARGS__]; \
[FBSDKLogger singleShotLogEntry:loggingBehavior logEntry:msg]; \
} \
}
#define FB_BASE_URL @"facebook.com"
+ (Class)resolveBoltsClassWithName:(NSString *)className;
@end