BFAppLinkNavigation.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) 2014, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. #import <Foundation/Foundation.h>
  11. #import <Bolts/BFAppLink.h>
  12. /*!
  13. The result of calling navigate on a BFAppLinkNavigation
  14. */
  15. typedef NS_ENUM(NSInteger, BFAppLinkNavigationType) {
  16. /*! Indicates that the navigation failed and no app was opened */
  17. BFAppLinkNavigationTypeFailure,
  18. /*! Indicates that the navigation succeeded by opening the URL in the browser */
  19. BFAppLinkNavigationTypeBrowser,
  20. /*! Indicates that the navigation succeeded by opening the URL in an app on the device */
  21. BFAppLinkNavigationTypeApp
  22. };
  23. @protocol BFAppLinkResolving;
  24. @class BFTask;
  25. /*!
  26. Represents a pending request to navigate to an App Link. Most developers will
  27. simply use navigateToURLInBackground: to open a URL, but developers can build
  28. custom requests with additional navigation and app data attached to them by
  29. creating BFAppLinkNavigations themselves.
  30. */
  31. @interface BFAppLinkNavigation : NSObject
  32. /*!
  33. The extras for the AppLinkNavigation. This will generally contain application-specific
  34. data that should be passed along with the request, such as advertiser or affiliate IDs or
  35. other such metadata relevant on this device.
  36. */
  37. @property (nonatomic, copy, readonly) NSDictionary *extras;
  38. /*!
  39. The al_applink_data for the AppLinkNavigation. This will generally contain data common to
  40. navigation attempts such as back-links, user agents, and other information that may be used
  41. in routing and handling an App Link request.
  42. */
  43. @property (nonatomic, copy, readonly) NSDictionary *appLinkData;
  44. /*! The AppLink to navigate to */
  45. @property (nonatomic, strong, readonly) BFAppLink *appLink;
  46. /*! Creates an AppLinkNavigation with the given link, extras, and App Link data */
  47. + (instancetype)navigationWithAppLink:(BFAppLink *)appLink
  48. extras:(NSDictionary *)extras
  49. appLinkData:(NSDictionary *)appLinkData;
  50. /*!
  51. Creates an NSDictionary with the correct format for iOS callback URLs,
  52. to be used as 'appLinkData' argument in the call to navigationWithAppLink:extras:appLinkData:
  53. */
  54. + (NSDictionary *)callbackAppLinkDataForAppWithName:(NSString *)appName url:(NSString *)url;
  55. /*! Performs the navigation */
  56. - (BFAppLinkNavigationType)navigate:(NSError **)error;
  57. /*! Returns a BFAppLink for the given URL */
  58. + (BFTask *)resolveAppLinkInBackground:(NSURL *)destination;
  59. /*! Returns a BFAppLink for the given URL using the given App Link resolution strategy */
  60. + (BFTask *)resolveAppLinkInBackground:(NSURL *)destination resolver:(id<BFAppLinkResolving>)resolver;
  61. /*! Navigates to a BFAppLink and returns whether it opened in-app or in-browser */
  62. + (BFAppLinkNavigationType)navigateToAppLink:(BFAppLink *)link error:(NSError **)error;
  63. /*!
  64. Returns a BFAppLinkNavigationType based on a BFAppLink.
  65. It's essentially a no-side-effect version of navigateToAppLink:error:,
  66. allowing apps to determine flow based on the link type (e.g. open an
  67. internal web view instead of going straight to the browser for regular links.)
  68. */
  69. + (BFAppLinkNavigationType)navigationTypeForLink:(BFAppLink *)link;
  70. /*!
  71. Return navigation type for current instance.
  72. No-side-effect version of navigate:
  73. */
  74. - (BFAppLinkNavigationType)navigationType;
  75. /*! Navigates to a URL (an asynchronous action) and returns a BFNavigationType */
  76. + (BFTask *)navigateToURLInBackground:(NSURL *)destination;
  77. /*!
  78. Navigates to a URL (an asynchronous action) using the given App Link resolution
  79. strategy and returns a BFNavigationType
  80. */
  81. + (BFTask *)navigateToURLInBackground:(NSURL *)destination resolver:(id<BFAppLinkResolving>)resolver;
  82. /*!
  83. Gets the default resolver to be used for App Link resolution. If the developer has not set one explicitly,
  84. a basic, built-in resolver will be used.
  85. */
  86. + (id<BFAppLinkResolving>)defaultResolver;
  87. /*!
  88. Sets the default resolver to be used for App Link resolution. Setting this to nil will revert the
  89. default resolver to the basic, built-in resolver provided by Bolts.
  90. */
  91. + (void)setDefaultResolver:(id<BFAppLinkResolving>)resolver;
  92. @end