commit | author | age
|
bad748
|
1 |
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved. |
W |
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 <UIKit/UIKit.h> |
|
20 |
|
e81c27
|
21 |
NS_ASSUME_NONNULL_BEGIN |
49b883
|
22 |
|
L |
23 |
#if TARGET_OS_TV |
|
24 |
|
|
25 |
// This is an unfortunate hack for Swift Package Manager support. |
|
26 |
// SPM does not allow us to conditionally exclude Swift files for compilation by platform. |
|
27 |
// |
|
28 |
// So to support tvOS with SPM we need to use runtime availability checks in the Swift files. |
|
29 |
// This means that even though the code in `LoginManager.swift` will never be run for tvOS |
|
30 |
// targets, it still needs to be able to compile. Hence we need to declare it here. |
|
31 |
// |
|
32 |
// The way to fix this is to remove extensions of ObjC types in Swift. |
|
33 |
|
|
34 |
@class LoginManagerLoginResult; |
|
35 |
|
|
36 |
typedef NS_ENUM(NSUInteger, LoginBehavior) { LoginBehaviorBrowser }; |
|
37 |
typedef NS_ENUM(NSUInteger, DefaultAudience) { DefaultAudienceFriends }; |
|
38 |
typedef void (^LoginManagerLoginResultBlock)(LoginManagerLoginResult *_Nullable result, |
|
39 |
NSError *_Nullable error); |
|
40 |
|
|
41 |
@interface LoginManager : NSObject |
|
42 |
|
|
43 |
@property (assign, nonatomic) LoginBehavior loginBehavior; |
|
44 |
@property (assign, nonatomic) DefaultAudience defaultAudience; |
|
45 |
|
|
46 |
- (void)logInWithPermissions:(NSArray<NSString *> *)permissions |
|
47 |
fromViewController:(nullable UIViewController *)fromViewController |
|
48 |
handler:(nullable LoginManagerLoginResultBlock)handler |
|
49 |
NS_SWIFT_NAME(logIn(permissions:from:handler:)); |
|
50 |
|
|
51 |
@end |
|
52 |
|
|
53 |
#else |
e81c27
|
54 |
|
bad748
|
55 |
@class FBSDKLoginManagerLoginResult; |
e81c27
|
56 |
|
H |
57 |
/// typedef for FBSDKLoginAuthType |
|
58 |
typedef NSString *const FBSDKLoginAuthType NS_TYPED_EXTENSIBLE_ENUM NS_SWIFT_NAME(LoginAuthType); |
|
59 |
|
|
60 |
/// Rerequest |
|
61 |
FOUNDATION_EXPORT FBSDKLoginAuthType FBSDKLoginAuthTypeRerequest; |
|
62 |
|
|
63 |
/// Reauthorize |
|
64 |
FOUNDATION_EXPORT FBSDKLoginAuthType FBSDKLoginAuthTypeReauthorize; |
bad748
|
65 |
|
9febd9
|
66 |
/** |
W |
67 |
Describes the call back to the FBSDKLoginManager |
13e53a
|
68 |
@param result the result of the authorization |
H |
69 |
@param error the authorization error, if any. |
bad748
|
70 |
*/ |
e81c27
|
71 |
typedef void (^FBSDKLoginManagerLoginResultBlock)(FBSDKLoginManagerLoginResult *_Nullable result, |
H |
72 |
NSError *_Nullable error) |
|
73 |
NS_SWIFT_NAME(LoginManagerLoginResultBlock); |
bad748
|
74 |
|
W |
75 |
|
9febd9
|
76 |
/** |
W |
77 |
FBSDKDefaultAudience enum |
bad748
|
78 |
|
9febd9
|
79 |
Passed to open to indicate which default audience to use for sessions that post data to Facebook. |
bad748
|
80 |
|
9febd9
|
81 |
|
W |
82 |
|
bad748
|
83 |
Certain operations such as publishing a status or publishing a photo require an audience. When the user |
W |
84 |
grants an application permission to perform a publish operation, a default audience is selected as the |
|
85 |
publication ceiling for the application. This enumerated value allows the application to select which |
|
86 |
audience to ask the user to grant publish permission for. |
|
87 |
*/ |
|
88 |
typedef NS_ENUM(NSUInteger, FBSDKDefaultAudience) |
|
89 |
{ |
9febd9
|
90 |
/** Indicates that the user's friends are able to see posts made by the application */ |
bad748
|
91 |
FBSDKDefaultAudienceFriends = 0, |
9febd9
|
92 |
/** Indicates that only the user is able to see posts made by the application */ |
bad748
|
93 |
FBSDKDefaultAudienceOnlyMe, |
9febd9
|
94 |
/** Indicates that all Facebook users are able to see posts made by the application */ |
bad748
|
95 |
FBSDKDefaultAudienceEveryone, |
e81c27
|
96 |
} NS_SWIFT_NAME(DefaultAudience); |
bad748
|
97 |
|
9febd9
|
98 |
/** |
W |
99 |
`FBSDKLoginManager` provides methods for logging the user in and out. |
|
100 |
|
|
101 |
`FBSDKLoginManager` works directly with `[FBSDKAccessToken currentAccessToken]` and |
bad748
|
102 |
sets the "currentAccessToken" upon successful authorizations (or sets `nil` in case of `logOut`). |
W |
103 |
|
|
104 |
You should check `[FBSDKAccessToken currentAccessToken]` before calling logIn* to see if there is |
|
105 |
a cached token available (typically in your viewDidLoad). |
|
106 |
|
|
107 |
If you are managing your own token instances outside of "currentAccessToken", you will need to set |
9febd9
|
108 |
"currentAccessToken" before calling logIn* to authorize further permissions on your tokens. |
bad748
|
109 |
*/ |
e81c27
|
110 |
NS_SWIFT_NAME(LoginManager) |
bad748
|
111 |
@interface FBSDKLoginManager : NSObject |
W |
112 |
|
9febd9
|
113 |
/** |
9f077b
|
114 |
Auth type |
H |
115 |
*/ |
e81c27
|
116 |
@property (strong, nonatomic) FBSDKLoginAuthType authType; |
9f077b
|
117 |
/** |
9febd9
|
118 |
the default audience. |
W |
119 |
|
|
120 |
you should set this if you intend to ask for publish permissions. |
bad748
|
121 |
*/ |
W |
122 |
@property (assign, nonatomic) FBSDKDefaultAudience defaultAudience; |
|
123 |
|
9febd9
|
124 |
/** |
e81c27
|
125 |
Logs the user in or authorizes additional permissions. |
13e53a
|
126 |
@param permissions the optional array of permissions. Note this is converted to NSSet and is only |
bad748
|
127 |
an NSArray for the convenience of literal syntax. |
13e53a
|
128 |
@param fromViewController the view controller to present from. If nil, the topmost view controller will be |
bad748
|
129 |
automatically determined as best as possible. |
13e53a
|
130 |
@param handler the callback. |
9febd9
|
131 |
|
e81c27
|
132 |
Use this method when asking for read permissions. You should only ask for permissions when they |
bad748
|
133 |
are needed and explain the value to the user. You can inspect the result.declinedPermissions to also |
W |
134 |
provide more information to the user if they decline permissions. |
|
135 |
|
|
136 |
This method will present UI the user. You typically should check if `[FBSDKAccessToken currentAccessToken]` |
|
137 |
already contains the permissions you need before asking to reduce unnecessary app switching. For example, |
|
138 |
you could make that check at viewDidLoad. |
9febd9
|
139 |
You can only do one login call at a time. Calling a login method before the completion handler is called |
W |
140 |
on a previous login will return an error. |
bad748
|
141 |
*/ |
e81c27
|
142 |
- (void)logInWithPermissions:(NSArray<NSString *> *)permissions |
H |
143 |
fromViewController:(nullable UIViewController *)fromViewController |
|
144 |
handler:(nullable FBSDKLoginManagerLoginResultBlock)handler |
|
145 |
NS_SWIFT_NAME(logIn(permissions:from:handler:)); |
49b883
|
146 |
|
L |
147 |
/** |
|
148 |
Logs the user in with the given deep link url. Will only log user in if the given url contains valid login data. |
|
149 |
@param url the deep link url |
|
150 |
@param handler the callback. |
|
151 |
|
|
152 |
This method should be called with the url from the openURL method. |
|
153 |
*/ |
|
154 |
- (void)logInWithURL:(NSURL *)url |
|
155 |
handler:(nullable FBSDKLoginManagerLoginResultBlock)handler |
|
156 |
NS_SWIFT_NAME(logIn(url:handler:)); |
13e53a
|
157 |
|
H |
158 |
/** |
|
159 |
Requests user's permission to reathorize application's data access, after it has expired due to inactivity. |
|
160 |
@param fromViewController the view controller to present from. If nil, the topmost view controller will be |
|
161 |
automatically determined as best as possible. |
|
162 |
@param handler the callback. |
|
163 |
Use this method when you need to reathorize your app's access to user data via Graph API, after such an access has expired. |
|
164 |
You should provide as much context to the user as possible as to why you need to reauthorize the access, the scope of |
|
165 |
access being reathorized, and what added value your app provides when the access is reathorized. |
|
166 |
You can inspect the result.declinedPermissions to also provide more information to the user if they decline permissions. |
|
167 |
This method will present UI the user. You typically should call this if `[FBSDKAccessToken isDataAccessExpired]` returns true. |
|
168 |
*/ |
|
169 |
- (void)reauthorizeDataAccess:(UIViewController *)fromViewController |
e81c27
|
170 |
handler:(FBSDKLoginManagerLoginResultBlock)handler |
H |
171 |
NS_SWIFT_NAME(reauthorizeDataAccess(from:handler:)); |
13e53a
|
172 |
|
9febd9
|
173 |
/** |
W |
174 |
Logs the user out |
|
175 |
|
|
176 |
This calls [FBSDKAccessToken setCurrentAccessToken:nil] and [FBSDKProfile setCurrentProfile:nil]. |
bad748
|
177 |
*/ |
W |
178 |
- (void)logOut; |
|
179 |
|
|
180 |
@end |
e81c27
|
181 |
|
49b883
|
182 |
#endif |
L |
183 |
|
e81c27
|
184 |
NS_ASSUME_NONNULL_END |