An example on MVVM(protocol) for architecturing iOS projects
Provide an example implementation of MVVM(protocol) for reference on how to architecture iOS projects
- iOS 11.0+
- Xcode 8
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 Twitter.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.
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.
Inside your App Delegate, initialize Twitter Kit with your application key and secret (paste your own key and secret).
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
Twitter.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>
<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>
Ivan Foong – @vonze21 – [email protected]
Distributed under the MIT license. See LICENSE
for more information.