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