commit | author | age
|
2e29a3
|
1 |
/* |
L |
2 |
* Copyright (c) Meta Platforms, Inc. and affiliates. |
|
3 |
* All rights reserved. |
|
4 |
* |
|
5 |
* This source code is licensed under the license found in the |
|
6 |
* LICENSE file in the root directory of this source tree. |
|
7 |
*/ |
|
8 |
|
|
9 |
#import <UIKit/UIKit.h> |
|
10 |
|
|
11 |
#import <FBSDKLoginKit/FBSDKLoginConfiguration.h> |
|
12 |
|
|
13 |
NS_ASSUME_NONNULL_BEGIN |
|
14 |
|
|
15 |
#if TARGET_OS_TV |
|
16 |
|
|
17 |
// This is an unfortunate hack for Swift Package Manager support. |
|
18 |
// SPM does not allow us to conditionally exclude Swift files for compilation by platform. |
|
19 |
// |
|
20 |
// So to support tvOS with SPM we need to use runtime availability checks in the Swift files. |
|
21 |
// This means that even though the code in `LoginManager.swift` will never be run for tvOS |
|
22 |
// targets, it still needs to be able to compile. Hence we need to declare it here. |
|
23 |
// |
|
24 |
// The way to fix this is to remove extensions of ObjC types in Swift. |
|
25 |
|
|
26 |
@class LoginManagerLoginResult; |
|
27 |
@class FBSDKLoginConfiguration; |
|
28 |
|
|
29 |
typedef NS_ENUM(NSUInteger, LoginBehavior) { LoginBehaviorBrowser, }; |
|
30 |
typedef NS_ENUM(NSUInteger, DefaultAudience) { DefaultAudienceFriends, }; |
|
31 |
|
|
32 |
typedef void (^LoginManagerLoginResultBlock)(LoginManagerLoginResult *_Nullable result, |
|
33 |
NSError *_Nullable error); |
|
34 |
|
|
35 |
@interface LoginManager : NSObject |
|
36 |
|
|
37 |
@property (nonatomic, assign) LoginBehavior loginBehavior; |
|
38 |
@property (nonatomic, assign) DefaultAudience defaultAudience; |
|
39 |
|
|
40 |
// UNCRUSTIFY_FORMAT_OFF |
|
41 |
- (void)logInWithPermissions:(NSArray<NSString *> *)permissions |
|
42 |
fromViewController:(nullable UIViewController *)fromViewController |
|
43 |
handler:(nullable LoginManagerLoginResultBlock)handler |
|
44 |
NS_SWIFT_NAME(logIn(permissions:from:handler:)); |
|
45 |
// UNCRUSTIFY_FORMAT_ON |
|
46 |
|
|
47 |
- (void)logInFromViewController:(nullable UIViewController *)viewController |
|
48 |
configuration:(FBSDKLoginConfiguration *)configuration |
|
49 |
completion:(LoginManagerLoginResultBlock)completion |
|
50 |
NS_REFINED_FOR_SWIFT; |
|
51 |
|
|
52 |
@end |
|
53 |
|
|
54 |
#else |
|
55 |
|
|
56 |
@class FBSDKLoginManagerLoginResult; |
|
57 |
|
|
58 |
/** |
|
59 |
Describes the call back to the FBSDKLoginManager |
|
60 |
@param result the result of the authorization |
|
61 |
@param error the authorization error, if any. |
|
62 |
*/ |
|
63 |
typedef void (^ FBSDKLoginManagerLoginResultBlock)(FBSDKLoginManagerLoginResult *_Nullable result, |
|
64 |
NSError *_Nullable error) |
|
65 |
NS_SWIFT_NAME(LoginManagerLoginResultBlock); |
|
66 |
|
|
67 |
/** |
|
68 |
FBSDKDefaultAudience enum |
|
69 |
|
|
70 |
Passed to openURL to indicate which default audience to use for sessions that post data to Facebook. |
|
71 |
|
|
72 |
Certain operations such as publishing a status or publishing a photo require an audience. When the user |
|
73 |
grants an application permission to perform a publish operation, a default audience is selected as the |
|
74 |
publication ceiling for the application. This enumerated value allows the application to select which |
|
75 |
audience to ask the user to grant publish permission for. |
|
76 |
*/ |
|
77 |
typedef NS_ENUM(NSUInteger, FBSDKDefaultAudience) { |
|
78 |
/** Indicates that the user's friends are able to see posts made by the application */ |
|
79 |
FBSDKDefaultAudienceFriends = 0, |
|
80 |
/** Indicates that only the user is able to see posts made by the application */ |
|
81 |
FBSDKDefaultAudienceOnlyMe, |
|
82 |
/** Indicates that all Facebook users are able to see posts made by the application */ |
|
83 |
FBSDKDefaultAudienceEveryone, |
|
84 |
} NS_SWIFT_NAME(DefaultAudience); |
|
85 |
|
|
86 |
/** |
|
87 |
`FBSDKLoginManager` provides methods for logging the user in and out. |
|
88 |
|
|
89 |
`FBSDKLoginManager` serves to help manage sessions represented by tokens for authentication, |
|
90 |
`AuthenticationToken`, and data access, `AccessToken`. |
|
91 |
|
|
92 |
You should check if the type of token you expect is present as a singleton instance, either `AccessToken.current` |
|
93 |
or `AuthenticationToken.current` before calling any of the login methods to see if there is a cached token |
|
94 |
available. A standard place to do this is in `viewDidLoad`. |
|
95 |
|
|
96 |
@warning If you are managing your own token instances outside of `AccessToken.current`, you will need to set |
|
97 |
`AccessToken.current` before calling any of the login methods to authorize further permissions on your tokens. |
|
98 |
*/ |
|
99 |
NS_SWIFT_NAME(LoginManager) |
|
100 |
@interface FBSDKLoginManager : NSObject |
|
101 |
|
|
102 |
/** |
|
103 |
the default audience. |
|
104 |
|
|
105 |
you should set this if you intend to ask for publish permissions. |
|
106 |
*/ |
|
107 |
@property (nonatomic, assign) FBSDKDefaultAudience defaultAudience; |
|
108 |
|
|
109 |
/** |
|
110 |
Logs the user in or authorizes additional permissions. |
|
111 |
|
|
112 |
@param permissions the optional array of permissions. Note this is converted to NSSet and is only |
|
113 |
an NSArray for the convenience of literal syntax. |
|
114 |
@param fromViewController the view controller to present from. If nil, the topmost view controller will be |
|
115 |
automatically determined as best as possible. |
|
116 |
@param handler the callback. |
|
117 |
|
|
118 |
Use this method when asking for read permissions. You should only ask for permissions when they |
|
119 |
are needed and explain the value to the user. You can inspect the `FBSDKLoginManagerLoginResultBlock`'s |
|
120 |
`result.declinedPermissions` to provide more information to the user if they decline permissions. |
|
121 |
You typically should check if `AccessToken.current` already contains the permissions you need before |
|
122 |
asking to reduce unnecessary login attempts. For example, you could perform that check in `viewDidLoad`. |
|
123 |
|
|
124 |
@warning You can only perform one login call at a time. Calling a login method before the completion handler is called |
|
125 |
on a previous login attempt will result in an error. |
|
126 |
@warning This method will present a UI to the user and thus should be called on the main thread. |
|
127 |
*/ |
|
128 |
|
|
129 |
// UNCRUSTIFY_FORMAT_OFF |
|
130 |
- (void)logInWithPermissions:(NSArray<NSString *> *)permissions |
|
131 |
fromViewController:(nullable UIViewController *)fromViewController |
|
132 |
handler:(nullable FBSDKLoginManagerLoginResultBlock)handler |
|
133 |
NS_SWIFT_NAME(logIn(permissions:from:handler:)); |
|
134 |
// UNCRUSTIFY_FORMAT_ON |
|
135 |
|
|
136 |
/** |
|
137 |
Logs the user in or authorizes additional permissions. |
|
138 |
|
|
139 |
@param viewController the view controller from which to present the login UI. If nil, the topmost view |
|
140 |
controller will be automatically determined and used. |
|
141 |
@param configuration the login configuration to use. |
|
142 |
@param completion the login completion handler. |
|
143 |
|
|
144 |
Use this method when asking for permissions. You should only ask for permissions when they |
|
145 |
are needed and the value should be explained to the user. You can inspect the |
|
146 |
`FBSDKLoginManagerLoginResultBlock`'s `result.declinedPermissions` to provide more information |
|
147 |
to the user if they decline permissions. |
|
148 |
To reduce unnecessary login attempts, you should typically check if `AccessToken.current` |
|
149 |
already contains the permissions you need. If it does, you probably do not need to call this method. |
|
150 |
|
|
151 |
@warning You can only perform one login call at a time. Calling a login method before the completion handler is called |
|
152 |
on a previous login attempt will result in an error. |
|
153 |
@warning This method will present a UI to the user and thus should be called on the main thread. |
|
154 |
*/ |
|
155 |
- (void)logInFromViewController:(nullable UIViewController *)viewController |
|
156 |
configuration:(FBSDKLoginConfiguration *)configuration |
|
157 |
completion:(FBSDKLoginManagerLoginResultBlock)completion |
|
158 |
NS_REFINED_FOR_SWIFT; |
|
159 |
|
|
160 |
/** |
|
161 |
Logs the user in with the given deep link url. Will only log user in if the given url contains valid login data. |
|
162 |
@param url the deep link url |
|
163 |
@param handler the callback. |
|
164 |
|
|
165 |
This method will present a UI to the user and thus should be called on the main thread. |
|
166 |
This method should be called with the url from the openURL method. |
|
167 |
|
|
168 |
@warning This method will present a UI to the user and thus should be called on the main thread. |
|
169 |
*/ |
|
170 |
|
|
171 |
// UNCRUSTIFY_FORMAT_OFF |
|
172 |
- (void)logInWithURL:(NSURL *)url |
|
173 |
handler:(nullable FBSDKLoginManagerLoginResultBlock)handler |
|
174 |
NS_SWIFT_NAME(logIn(url:handler:)) |
|
175 |
DEPRECATED_MSG_ATTRIBUTE("`logInWithURL:handler:` is deprecated and will be removed in the next major release"); |
|
176 |
// UNCRUSTIFY_FORMAT_ON |
|
177 |
|
|
178 |
/** |
|
179 |
Requests user's permission to reathorize application's data access, after it has expired due to inactivity. |
|
180 |
@param fromViewController the view controller from which to present the login UI. If nil, the topmost view |
|
181 |
controller will be automatically determined and used. |
|
182 |
@param handler the callback. |
|
183 |
|
|
184 |
Use this method when you need to reathorize your app's access to user data via the Graph API. |
|
185 |
You should only call this after access has expired. |
|
186 |
You should provide as much context to the user as possible as to why you need to reauthorize the access, the |
|
187 |
scope of access being reathorized, and what added value your app provides when the access is reathorized. |
|
188 |
You can inspect the `result.declinedPermissions` to determine if you should provide more information to the |
|
189 |
user based on any declined permissions. |
|
190 |
|
|
191 |
@warning This method will reauthorize using a `LoginConfiguration` with `FBSDKLoginTracking` set to `.enabled`. |
|
192 |
@warning This method will present UI the user. You typically should call this if `AccessToken.isDataAccessExpired` is true. |
|
193 |
*/ |
|
194 |
|
|
195 |
// UNCRUSTIFY_FORMAT_OFF |
|
196 |
- (void)reauthorizeDataAccess:(UIViewController *)fromViewController |
|
197 |
handler:(FBSDKLoginManagerLoginResultBlock)handler |
|
198 |
NS_SWIFT_NAME(reauthorizeDataAccess(from:handler:)); |
|
199 |
// UNCRUSTIFY_FORMAT_ON |
|
200 |
|
|
201 |
/** |
|
202 |
Logs the user out |
|
203 |
|
|
204 |
This nils out the singleton instances of `AccessToken` `AuthenticationToken` and `Profle`. |
|
205 |
|
|
206 |
@note This is only a client side logout. It will not log the user out of their Facebook account. |
|
207 |
*/ |
|
208 |
- (void)logOut; |
|
209 |
|
|
210 |
@end |
|
211 |
|
|
212 |
#endif |
|
213 |
|
|
214 |
NS_ASSUME_NONNULL_END |