PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/Internal/FBSDKInternalUtility.h

https://gitlab.com/maheshm255/B4U
C Header | 336 lines | 86 code | 45 blank | 205 comment | 1 complexity | 05ca7a64cd3829c3d3f3671003dcabc3 MD5 | raw file
  1. // Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  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. #import <Foundation/Foundation.h>
  19. #import <UIKit/UIKit.h>
  20. #define FBSDK_CANOPENURL_FACEBOOK @"fbauth2"
  21. #define FBSDK_CANOPENURL_MESSENGER @"fb-messenger-api"
  22. typedef NS_ENUM(int32_t, FBSDKUIKitVersion)
  23. {
  24. FBSDKUIKitVersion_6_0 = 0x0944,
  25. FBSDKUIKitVersion_6_1 = 0x094C,
  26. FBSDKUIKitVersion_7_0 = 0x0B57,
  27. FBSDKUIKitVersion_7_1 = 0x0B77,
  28. FBSDKUIKitVersion_8_0 = 0x0CF6,
  29. };
  30. @interface FBSDKInternalUtility : NSObject
  31. /*!
  32. @abstract Constructs the scheme for apps that come to the current app through the bridge.
  33. */
  34. + (NSString *)appURLScheme;
  35. /*!
  36. @abstract Constructs an URL for the current app.
  37. @param host The host for the URL.
  38. @param path The path for the URL.
  39. @param queryParameters The query parameters for the URL. This will be converted into a query string.
  40. @param errorRef If an error occurs, upon return contains an NSError object that describes the problem.
  41. @return The app URL.
  42. */
  43. + (NSURL *)appURLWithHost:(NSString *)host
  44. path:(NSString *)path
  45. queryParameters:(NSDictionary *)queryParameters
  46. error:(NSError *__autoreleasing *)errorRef;
  47. /*!
  48. @abstract Parses an FB url's query params (and potentially fragment) into a dictionary.
  49. @param url The FB url.
  50. @return A dictionary with the key/value pairs.
  51. */
  52. + (NSDictionary *)dictionaryFromFBURL:(NSURL *)url;
  53. /*!
  54. @abstract Adds an object to an array if it is not nil.
  55. @param array The array to add the object to.
  56. @param object The object to add to the array.
  57. */
  58. + (void)array:(NSMutableArray *)array addObject:(id)object;
  59. /*!
  60. @abstract Returns bundle for returning localized strings
  61. @discussion We assume a convention of a bundle named FBSDKStrings.bundle, otherwise we
  62. return the main bundle.
  63. */
  64. + (NSBundle *)bundleForStrings;
  65. /*!
  66. @abstract Converts simple value types to the string equivelant for serializing to a request query or body.
  67. @param value The value to be converted.
  68. @return The value that may have been converted if able (otherwise the input param).
  69. */
  70. + (id)convertRequestValue:(id)value;
  71. /*!
  72. @abstract Gets the milliseconds since the Unix Epoch.
  73. @discussion Changes in the system clock will affect this value.
  74. @return The number of milliseconds since the Unix Epoch.
  75. */
  76. + (unsigned long)currentTimeInMilliseconds;
  77. /*!
  78. @abstract Sets an object for a key in a dictionary if it is not nil.
  79. @param dictionary The dictionary to set the value for.
  80. @param object The value to set after serializing to JSON.
  81. @param key The key to set the value for.
  82. @param errorRef If an error occurs, upon return contains an NSError object that describes the problem.
  83. @return NO if an error occurred while serializing the object, otherwise YES.
  84. */
  85. + (BOOL)dictionary:(NSMutableDictionary *)dictionary
  86. setJSONStringForObject:(id)object
  87. forKey:(id<NSCopying>)key
  88. error:(NSError *__autoreleasing *)errorRef;
  89. /*!
  90. @abstract Sets an object for a key in a dictionary if it is not nil.
  91. @param dictionary The dictionary to set the value for.
  92. @param object The value to set.
  93. @param key The key to set the value for.
  94. */
  95. + (void)dictionary:(NSMutableDictionary *)dictionary setObject:(id)object forKey:(id<NSCopying>)key;
  96. /*!
  97. @abstract Constructs a Facebook URL.
  98. @param hostPrefix The prefix for the host, such as 'm', 'graph', etc.
  99. @param path The path for the URL. This may or may not include a version.
  100. @param queryParameters The query parameters for the URL. This will be converted into a query string.
  101. @param errorRef If an error occurs, upon return contains an NSError object that describes the problem.
  102. @return The Facebook URL.
  103. */
  104. + (NSURL *)facebookURLWithHostPrefix:(NSString *)hostPrefix
  105. path:(NSString *)path
  106. queryParameters:(NSDictionary *)queryParameters
  107. error:(NSError *__autoreleasing *)errorRef;
  108. /*!
  109. @abstract Constructs a Facebook URL.
  110. @param hostPrefix The prefix for the host, such as 'm', 'graph', etc.
  111. @param path The path for the URL. This may or may not include a version.
  112. @param queryParameters The query parameters for the URL. This will be converted into a query string.
  113. @param defaultVersion A version to add to the URL if none is found in the path.
  114. @param errorRef If an error occurs, upon return contains an NSError object that describes the problem.
  115. @return The Facebook URL.
  116. */
  117. + (NSURL *)facebookURLWithHostPrefix:(NSString *)hostPrefix
  118. path:(NSString *)path
  119. queryParameters:(NSDictionary *)queryParameters
  120. defaultVersion:(NSString *)defaultVersion
  121. error:(NSError *__autoreleasing *)errorRef;
  122. /*!
  123. @abstract Tests whether the supplied URL is a valid URL for opening in the browser.
  124. @param URL The URL to test.
  125. @return YES if the URL refers to an http or https resource, otherwise NO.
  126. */
  127. + (BOOL)isBrowserURL:(NSURL *)URL;
  128. /*!
  129. @abstract Tests whether the supplied bundle identifier references a Facebook app.
  130. @param bundleIdentifier The bundle identifier to test.
  131. @return YES if the bundle identifier refers to a Facebook app, otherwise NO.
  132. */
  133. + (BOOL)isFacebookBundleIdentifier:(NSString *)bundleIdentifier;
  134. /*!
  135. @abstract Tests whether the operating system is at least the specified version.
  136. @param version The version to test against.
  137. @return YES if the operating system is greater than or equal to the specified version, otherwise NO.
  138. */
  139. + (BOOL)isOSRunTimeVersionAtLeast:(NSOperatingSystemVersion)version;
  140. /*!
  141. @abstract Tests whether the supplied bundle identifier references the Safari app.
  142. @param bundleIdentifier The bundle identifier to test.
  143. @return YES if the bundle identifier refers to the Safari app, otherwise NO.
  144. */
  145. + (BOOL)isSafariBundleIdentifier:(NSString *)bundleIdentifier;
  146. /*!
  147. @abstract Tests whether the UIKit version that the current app was linked to is at least the specified version.
  148. @param version The version to test against.
  149. @return YES if the linked UIKit version is greater than or equal to the specified version, otherwise NO.
  150. */
  151. + (BOOL)isUIKitLinkTimeVersionAtLeast:(FBSDKUIKitVersion)version;
  152. /*!
  153. @abstract Tests whether the UIKit version in the runtime is at least the specified version.
  154. @param version The version to test against.
  155. @return YES if the runtime UIKit version is greater than or equal to the specified version, otherwise NO.
  156. */
  157. + (BOOL)isUIKitRunTimeVersionAtLeast:(FBSDKUIKitVersion)version;
  158. /*!
  159. @abstract Converts an object into a JSON string.
  160. @param object The object to convert to JSON.
  161. @param errorRef If an error occurs, upon return contains an NSError object that describes the problem.
  162. @param invalidObjectHandler Handles objects that are invalid, returning a replacement value or nil to ignore.
  163. @return A JSON string or nil if the object cannot be converted to JSON.
  164. */
  165. + (NSString *)JSONStringForObject:(id)object
  166. error:(NSError *__autoreleasing *)errorRef
  167. invalidObjectHandler:(id(^)(id object, BOOL *stop))invalidObjectHandler;
  168. /*!
  169. @abstract Checks equality between 2 objects.
  170. @discussion Checks for pointer equality, nils, isEqual:.
  171. @param object The first object to compare.
  172. @param other The second object to compare.
  173. @result YES if the objects are equal, otherwise NO.
  174. */
  175. + (BOOL)object:(id)object isEqualToObject:(id)other;
  176. /*!
  177. @abstract Converts a JSON string into an object
  178. @param string The JSON string to convert.
  179. @param errorRef If an error occurs, upon return contains an NSError object that describes the problem.
  180. @return An NSDictionary, NSArray, NSString or NSNumber containing the object representation, or nil if the string
  181. cannot be converted.
  182. */
  183. + (id)objectForJSONString:(NSString *)string error:(NSError *__autoreleasing *)errorRef;
  184. /*!
  185. @abstract The version of the operating system on which the process is executing.
  186. */
  187. + (NSOperatingSystemVersion)operatingSystemVersion;
  188. /*!
  189. @abstract Constructs a query string from a dictionary.
  190. @param dictionary The dictionary with key/value pairs for the query string.
  191. @param errorRef If an error occurs, upon return contains an NSError object that describes the problem.
  192. @param invalidObjectHandler Handles objects that are invalid, returning a replacement value or nil to ignore.
  193. @result Query string representation of the parameters.
  194. */
  195. + (NSString *)queryStringWithDictionary:(NSDictionary *)dictionary
  196. error:(NSError *__autoreleasing *)errorRef
  197. invalidObjectHandler:(id(^)(id object, BOOL *stop))invalidObjectHandler;
  198. /*!
  199. @abstract Tests whether the orientation should be manually adjusted for views outside of the root view controller.
  200. @discussion With the legacy layout the developer must worry about device orientation when working with views outside of
  201. the window's root view controller and apply the correct rotation transform and/or swap a view's width and height
  202. values. If the application was linked with UIKit on iOS 7 or earlier or the application is running on iOS 7 or earlier
  203. then we need to use the legacy layout code. Otherwise if the application was linked with UIKit on iOS 8 or later and
  204. the application is running on iOS 8 or later, UIKit handles all of the rotation complexity and the origin is always in
  205. the top-left and no rotation transform is necessary.
  206. @return YES if if the orientation must be manually adjusted, otherwise NO.
  207. */
  208. + (BOOL)shouldManuallyAdjustOrientation;
  209. /*!
  210. @abstract Constructs an NSURL.
  211. @param scheme The scheme for the URL.
  212. @param host The host for the URL.
  213. @param path The path for the URL.
  214. @param queryParameters The query parameters for the URL. This will be converted into a query string.
  215. @param errorRef If an error occurs, upon return contains an NSError object that describes the problem.
  216. @return The URL.
  217. */
  218. + (NSURL *)URLWithScheme:(NSString *)scheme
  219. host:(NSString *)host
  220. path:(NSString *)path
  221. queryParameters:(NSDictionary *)queryParameters
  222. error:(NSError *__autoreleasing *)errorRef;
  223. /*!
  224. * @abstract Deletes all the cookies in the NSHTTPCookieStorage for Facebook web dialogs
  225. */
  226. + (void)deleteFacebookCookies;
  227. /*!
  228. @abstract Extracts permissions from a response fetched from me/permissions
  229. @param responseObject the response
  230. @param grantedPermissions the set to add granted permissions to
  231. @param declinedPermissions the set to add decliend permissions to.
  232. */
  233. + (void)extractPermissionsFromResponse:(NSDictionary *)responseObject
  234. grantedPermissions:(NSMutableSet *)grantedPermissions
  235. declinedPermissions:(NSMutableSet *)declinedPermissions;
  236. /*!
  237. @abstract Registers a transient object so that it will not be deallocated until unregistered
  238. @param object The transient object
  239. */
  240. + (void)registerTransientObject:(id)object;
  241. /*!
  242. @abstract Unregisters a transient object that was previously registered with registerTransientObject:
  243. @param object The transient object
  244. */
  245. + (void)unregisterTransientObject:(__weak id)object;
  246. /*!
  247. @abstract validates that the app ID is non-nil, throws an NSException if nil.
  248. */
  249. + (void)validateAppID;
  250. /*!
  251. @abstract validates that the right URL schemes are registered, throws an NSException if not.
  252. */
  253. + (void)validateURLSchemes;
  254. /*!
  255. @abstract Attempts to find the first UIViewController in the view's responder chain. Returns nil if not found.
  256. */
  257. + (UIViewController *)viewControllerforView:(UIView*)view;
  258. /*!
  259. @abstract returns true if the url scheme is registered in the CFBundleURLTypes
  260. */
  261. + (BOOL)isRegisteredURLScheme:(NSString *)urlScheme;
  262. /*!
  263. @abstract returns currently displayed top view controller.
  264. */
  265. + (UIViewController *)topMostViewController;
  266. /*
  267. @abstract Checks if the permission is a publish permission.
  268. */
  269. + (BOOL)isPublishPermission:(NSString *)permission;
  270. /*
  271. @abstract Checks if the set of permissions are all read permissions.
  272. */
  273. + (BOOL)areAllPermissionsReadPermissions:(NSSet *)permissions;
  274. /*
  275. @abstract Checks if the set of permissions are all publish permissions.
  276. */
  277. + (BOOL)areAllPermissionsPublishPermissions:(NSSet *)permissions;
  278. #pragma mark - FB Apps Installed
  279. + (BOOL)isFacebookAppInstalled;
  280. + (BOOL)isMessengerAppInstalled;
  281. + (void)checkRegisteredCanOpenURLScheme:(NSString *)urlScheme;
  282. + (BOOL)isRegisteredCanOpenURLScheme:(NSString *)urlScheme;
  283. #define FBSDKConditionalLog(condition, loggingBehavior, desc, ...) \
  284. { \
  285. if (!(condition)) { \
  286. NSString *msg = [NSString stringWithFormat:(desc), ##__VA_ARGS__]; \
  287. [FBSDKLogger singleShotLogEntry:loggingBehavior logEntry:msg]; \
  288. } \
  289. }
  290. #define FB_BASE_URL @"facebook.com"
  291. @end