FBSDKAppLinkNavigation.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 "FBSDKAppLink.h"
  20. #import "FBSDKAppLinkResolving.h"
  21. NS_ASSUME_NONNULL_BEGIN
  22. /*!
  23. The result of calling navigate on a FBSDKAppLinkNavigation
  24. */
  25. typedef NS_ENUM(NSInteger, FBSDKAppLinkNavigationType) {
  26. /*! Indicates that the navigation failed and no app was opened */
  27. FBSDKAppLinkNavigationTypeFailure,
  28. /*! Indicates that the navigation succeeded by opening the URL in the browser */
  29. FBSDKAppLinkNavigationTypeBrowser,
  30. /*! Indicates that the navigation succeeded by opening the URL in an app on the device */
  31. FBSDKAppLinkNavigationTypeApp
  32. };
  33. /**
  34. Describes the callback for appLinkFromURLInBackground.
  35. @param navType the FBSDKAppLink representing the deferred App Link
  36. @param error the error during the request, if any
  37. */
  38. typedef void (^FBSDKAppLinkNavigationHandler)(FBSDKAppLinkNavigationType navType, NSError * _Nullable error);
  39. /*!
  40. Represents a pending request to navigate to an App Link. Most developers will
  41. simply use navigateToURLInBackground: to open a URL, but developers can build
  42. custom requests with additional navigation and app data attached to them by
  43. creating FBSDKAppLinkNavigations themselves.
  44. */
  45. NS_EXTENSION_UNAVAILABLE_IOS("Not available in app extension")
  46. @interface FBSDKAppLinkNavigation : NSObject
  47. /*!
  48. The extras for the AppLinkNavigation. This will generally contain application-specific
  49. data that should be passed along with the request, such as advertiser or affiliate IDs or
  50. other such metadata relevant on this device.
  51. */
  52. @property (nonatomic, copy, readonly) NSDictionary<NSString *, id> *extras;
  53. /*!
  54. The al_applink_data for the AppLinkNavigation. This will generally contain data common to
  55. navigation attempts such as back-links, user agents, and other information that may be used
  56. in routing and handling an App Link request.
  57. */
  58. @property (nonatomic, copy, readonly) NSDictionary<NSString *, id> *appLinkData;
  59. /*! The AppLink to navigate to */
  60. @property (nonatomic, strong, readonly) FBSDKAppLink *appLink;
  61. /*!
  62. Return navigation type for current instance.
  63. No-side-effect version of navigate:
  64. */
  65. @property (nonatomic, readonly) FBSDKAppLinkNavigationType navigationType;
  66. /*! Creates an AppLinkNavigation with the given link, extras, and App Link data */
  67. + (instancetype)navigationWithAppLink:(FBSDKAppLink *)appLink
  68. extras:(NSDictionary<NSString *, id> *)extras
  69. appLinkData:(NSDictionary<NSString *, id> *)appLinkData;
  70. /*!
  71. Creates an NSDictionary with the correct format for iOS callback URLs,
  72. to be used as 'appLinkData' argument in the call to navigationWithAppLink:extras:appLinkData:
  73. */
  74. + (NSDictionary<NSString *, NSDictionary<NSString *, NSString *> *> *)callbackAppLinkDataForAppWithName:(NSString *)appName
  75. url:(NSString *)url;
  76. /*! Performs the navigation */
  77. - (FBSDKAppLinkNavigationType)navigate:(NSError *__autoreleasing *)error;
  78. /*! Returns a FBSDKAppLink for the given URL */
  79. + (void)resolveAppLink:(NSURL *)destination handler:(FBSDKAppLinkFromURLHandler)handler;
  80. /*! Returns a FBSDKAppLink for the given URL using the given App Link resolution strategy */
  81. + (void)resolveAppLink:(NSURL *)destination
  82. resolver:(id<FBSDKAppLinkResolving>)resolver
  83. handler:(FBSDKAppLinkFromURLHandler)handler;
  84. /*! Navigates to a FBSDKAppLink and returns whether it opened in-app or in-browser */
  85. + (FBSDKAppLinkNavigationType)navigateToAppLink:(FBSDKAppLink *)link error:(NSError *__autoreleasing *)error;
  86. /*!
  87. Returns a FBSDKAppLinkNavigationType based on a FBSDKAppLink.
  88. It's essentially a no-side-effect version of navigateToAppLink:error:,
  89. allowing apps to determine flow based on the link type (e.g. open an
  90. internal web view instead of going straight to the browser for regular links.)
  91. */
  92. + (FBSDKAppLinkNavigationType)navigationTypeForLink:(FBSDKAppLink *)link;
  93. /*! Navigates to a URL (an asynchronous action) and returns a FBSDKNavigationType */
  94. + (void)navigateToURL:(NSURL *)destination handler:(FBSDKAppLinkNavigationHandler)handler;
  95. /*!
  96. Navigates to a URL (an asynchronous action) using the given App Link resolution
  97. strategy and returns a FBSDKNavigationType
  98. */
  99. + (void)navigateToURL:(NSURL *)destination
  100. resolver:(id<FBSDKAppLinkResolving>)resolver
  101. handler:(FBSDKAppLinkNavigationHandler)handler;
  102. /*!
  103. Gets the default resolver to be used for App Link resolution. If the developer has not set one explicitly,
  104. a basic, built-in resolver will be used.
  105. */
  106. + (id<FBSDKAppLinkResolving>)defaultResolver;
  107. /*!
  108. Sets the default resolver to be used for App Link resolution. Setting this to nil will revert the
  109. default resolver to the basic, built-in resolver provided by FBSDK.
  110. */
  111. + (void)setDefaultResolver:(id<FBSDKAppLinkResolving>)resolver;
  112. @end
  113. NS_ASSUME_NONNULL_END