1 //
2 // Twitter.h
3 //
4 // Copyright (c) 2015 Twitter. All rights reserved.
5 //
6
7 #import <TwitterCore/TWTRSession.h>
8 #import "TWTRAPIClient.h"
9 #import <UIKit/UIKit.h>
10
11 @class TWTRSessionStore;
12
13 NS_ASSUME_NONNULL_BEGIN
14
15 typedef NS_OPTIONS(NSInteger, TWTRLoginMethod) {
16
17 /**
18 * Attempts to log the user in with the system accounts.
19 * This log in method will only grant limited application permissions to
20 * the returned oauth token. If you would like to have more
21 * application permissions granted you must use the TWTRLoginMethodWebBased
22 * and configure your application correctly.
23 */
24 TWTRLoginMethodSystemAccounts = 1 << 0,
25
26 /**
27 * Presents a web view that allows the user to log in. Will use
28 * either UIWebView or SFSafariViewController depending on iOS
29 * version and the presence of a custom URL scheme for auth
30 * redirects.
31 *
32 * This method will allow the developer to request more application
33 * permissions. To learn more about configuring your application to
34 * have higher levels of permissions.
35 * Visit https://dev.twitter.com/oauth/overview/application-permission-model for
36 * more information about Twitter's application permission model.
37 */
38 TWTRLoginMethodWebBased = 1 << 1,
39
40 /**
41 * Presents a web view that doesn't use any cached sessions
42 * from Safari. Allows the developer to provide multi-user
43 * functionality with several Twitter accounts.
44 */
45 TWTRLoginMethodWebBasedForceLogin = 1 << 2,
46
47 /**
48 * Picks the first available log in method. The order in which
49 * methods are checked is TWTRLoginMethodSystemAccounts -> TWTRLoginMethodWebBased.
50 */
51 TWTRLoginMethodAll = TWTRLoginMethodSystemAccounts | TWTRLoginMethodWebBased
52 };
53
54
55 /**
56 * The central class of the Twitter Kit.
57 * @note This class can only be used from the main thread.
58 */
59 @interface Twitter : NSObject
60
61 /**
62 * Returns the Twitter singleton.
63 *
64 * @return The Twitter singleton.
65 */
66 + (Twitter *)sharedInstance;
67
68 /**
69 * Start Twitter with your consumer key and secret. These will override any credentials
70 * present in your applications Info.plist.
71 *
72 * You do not need to call this method unless you wish to provide credentials other than those
73 * in your Info.plist.
74 *
75 * @param consumerKey Your Twitter application's consumer key.
76 * @param consumerSecret Your Twitter application's consumer secret.
77 */
78 - (void)startWithConsumerKey:(NSString *)consumerKey consumerSecret:(NSString *)consumerSecret;
79
80 /**
81 * Start Twitter with a consumer key, secret, and keychain access group. See -[Twitter startWithConsumerKey:consumerSecret:]
82 *
83 * @param consumerKey Your Twitter application's consumer key.
84 * @param consumerSecret Your Twitter application's consumer secret.
85 * @param accessGroup An optional keychain access group to apply to session objects stored in the keychain.
86 *
87 * @note In the majority of situations applications will not need to specify an access group to use with Twitter sessions.
88 * This value is only needed if you plan to share credentials with another application that you control or if you are
89 * using TwitterKit with an app extension.
90 */
91 - (void)startWithConsumerKey:(NSString *)consumerKey consumerSecret:(NSString *)consumerSecret accessGroup:(nullable NSString *)accessGroup;
92
93 /**
94 * The current version of this kit.
95 */
96 @property (nonatomic, copy, readonly) NSString *version;
97
98 /**
99 * Authentication configuration details. Encapsulates the `consumerKey` and `consumerSecret` credentials required to authenticate a Twitter application.
100 */
101 @property (nonatomic, readonly) TWTRAuthConfig *authConfig;
102
103 /**
104 * Session store exposing methods to fetch and manage active sessions. Applications that need to manage
105 * multiple users should use the session store to authenticate and log out users.
106 */
107 @property (nonatomic, readonly) TWTRSessionStore *sessionStore;
108
109 /**
110 * Triggers user authentication with Twitter.
111 *
112 * This method will present UI to allow the user to log in if there are no saved Twitter login credentials.
113 * This method is equivalent to calling loginWithMethods:completion: with TWTRLoginMethodAll.
114 *
115 * @param completion The completion block will be called after authentication is successful or if there is an error.
116 * @warning This method requires that you have set up your `consumerKey` and `consumerSecret`.
117 */
118 - (void)logInWithCompletion:(TWTRLogInCompletion)completion;
119
120 /**
121 * Triggers user authentication with Twitter.
122 *
123 * This method will attempt to log the user in based on the specified log in methods. If multiple methods
124 * are specified the system account method will be attempted first.
125 *
126 * @param completion The completion block will be called after authentication is successful or if there is an error.
127 * @warning This method requires that you have set up your `consumerKey` and `consumerSecret`.
128 */
129 - (void)logInWithMethods:(TWTRLoginMethod)methods completion:(TWTRLogInCompletion)completion;
130
131 /**
132 * Triggers user authentication with Twitter. Allows the developer to specify the presenting view controller.
133 *
134 * This method will present UI to allow the user to log in if there are no saved Twitter login credentials.
135 *
136 * @param viewController The view controller that will be used to present the authentication view.
137 * @param completion The completion block will be called after authentication is successful or if there is an error.
138 * @warning This method requires that you have set up your `consumerKey` and `consumerSecret`.
139 */
140 - (void)logInWithViewController:(nullable UIViewController *)viewController completion:(TWTRLogInCompletion)completion;
141
142 /**
143 * Triggers user authentication with Twitter. Allows the developer to specify the presenting view controller.
144 *
145 * This method will attempt to log the user in based on the specified log in methods. If multiple methods
146 * are specified the system account method will be attempted first.
147 *
148 * @param viewController The view controller that will be used to present the authentication view.
149 * @param completion The completion block will be called after authentication is successful or if there is an error.
150 * @warning This method requires that you have set up your `consumerKey` and `consumerSecret`.
151 */
152 - (void)logInWithViewController:(nullable UIViewController *)viewController methods:(TWTRLoginMethod)methods completion:(TWTRLogInCompletion)completion;
153
154 /**
155 * Finish the `SFSafariViewController` authentication loop. This method should
156 * be called from application:openURL:options inside the application delegate.
157 *
158 * This method will verify an authentication token sent by the Twitter API to
159 * finish the web-based authentication flow.
160 *
161 * @param application The `UIApplication` instance received as a parameter.
162 * @param url The `NSURL` instance received as a parameter.
163 * @param options The options dictionary received as a parameter.
164 *
165 * @return Boolean specifying whether this URL was handled
166 * by Twitter Kit or not.
167 */
168 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *)options;
169
170 @end
171
172 NS_ASSUME_NONNULL_END