-
Notifications
You must be signed in to change notification settings - Fork 448
Installation
Twitter requires that all API requests be authenticated with tokens that
can be traced back to an individual Twitter App. If you already have
keys for a Twitter app you can pass them directly to the
TWTRTwitter.sharedInstance().start()
method.
To create a new Twitter app or use existing Twitter app, visit Twitter apps dashboard and copy the keys from the "Keys and Access Tokens" tab of your app page.
To add call back URL:
- In Twitter apps dashboard, find your application and go to the permissions tab.
- Select the appropriate permissions for your needs (e.g. "Read and write")
- If you are using login, add a placeholder URL in the Callback URL field (eg. "http://placeholder.com").
- Click update settings.
NOTE: Although the callback URL will not be requested by Twitter Kit in your app, it must be set to a valid URL for the app to work with the SDK.
To add Twitter Kit to your app, simply add the TwitterKit
pod to your Podfile:
target 'MyApp' do
use_frameworks!
pod 'TwitterKit'
end
Then in your terminal run pod install
, and finally
pod update TwitterKit
to make sure you have the latest
version.
If you don't have have CocoaPods set up for your app, you can run
pod init
from the root of your project directory.
To install TwitterKit for iOS using Carthage, add the following lines to your Cartfile. For more information about how to set up Carthage and your Cartfile, see here.
binary "https://ton.twimg.com/syndication/twitterkit/ios/TwitterKit.json"
binary "https://ton.twimg.com/syndication/twitterkit/ios/TwitterCore.json"
After running carthage update
, add TwitterKit.framework
and TwitterShareExtensionUI.framework
to the Linked Frameworks and Binaries section under General of your App target. In addition to that, make sure that when you are adding the copy-frameworks run script for Carthage that you add the following input paths:
$(SRCROOT)/Carthage/Build/iOS/TwitterCore.framework
$(SRCROOT)/Carthage/Build/iOS/TwitterKit.framework
$(SRCROOT)/Carthage/Build/iOS/TwitterShareExtensionUI.framework
Make sure that the run script phase is after your Link Binaries with Libraries phase to prevent issues with properly archiving your iOS application.
- Download and unzip Twitter Kit.
- Drag contents to the root of your project in Xcode
- Add TwitterKit to "Embedded Binaries" in your Xcode project settings
- Add TwitterKit and TwitterCore to "Linked Frameworks and Libraries" in your Xcode project settings
NOTE: Make sure 'Copy items if needed' is checked when prompted for options in Xcode.
Make sure to import the framework header:
#import <TwitterKit/TwitterKit.h>
If using Swift you will need to add it to your Objective-C bridging header
Inside your App Delegate, initialize Twitter Kit with your application key and secret (paste your own key and secret).
// Objective C
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[Twitter sharedInstance] startWithConsumerKey:@"hTpkPVU4pThkM0" consumerSecret:@"ovEqziMzLpUOF163Qg2mj"];
}
// Swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
TWTRTwitter.sharedInstance().start(withConsumerKey:"hTpkPVU4pThkM0", consumerSecret:"ovEqziMzLpUOF163Qg2mj")
return true
}
Twitter Kit looks for a URL scheme in the format
twitterkit-<consumerKey>
, where
consumerKey
is your application's Twitter API key, e.g.
twitterkit-dwLf79lNQfsJ
.
You can find your consumer key in the Twitter app dashboard.
In your app's Info.plist
, add URL Schemes by adding code below after <dict>
// Info.plist
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>twitterkit-<consumerKey></string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>twitter</string>
<string>twitterauth</string>
</array>
Once Twitter Kit has been installed, see the following sections for further examples: