CocoaPods trunk is moving to be read-only. Read more on the blog, there are 17 months to go.
TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Nov 2016 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✗ |
Maintained by Fernando Bass.
Depends on: | |
OAuthSwift | ~> 1.0 |
SwiftyJSON | ~> 3.1 |
Alamofire | ~> 4.0 |
A library to allow access to Medium API for any Swift iOS application.
pod 'MediumSDKSwift'
and run pod install
in the directory to load dependencies.
Add your MEDIUM_CLIENT_ID
, MEDIUM_CLIENT_SECRET
, MEDIUM_CALLBACK_URL
in Build settings
-> User-Define
In the project right click on your Info.plist
file, choose “Open As” - “Source code” and add these lines :
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleURLSchemes</key>
<array>
<string>mediumswift</string>
</array>
</dict>
</array>
<key>MediumCallbackURL</key>
<string>$(MEDIUM_CALLBACK_URL)</string>
<key>MediumClientID</key>
<string>$(MEDIUM_CLIENT_ID)</string>
<key>MediumClientSecret</key>
<string>$(MEDIUM_CLIENT_SECRET)</string>
right before the tag.
Handle the callback in App Delegate:
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
if (url.host == "mediumswift-callback") {
OAuthSwift.handleOpenURL(url)
}
return true
}
Note that the redirect is done via a free Heroku app and it’s highly recommended to setup your own redirect service by cloning and running this repo (courtesy of the original oauthswift.herokuapp.com repo). Change all the mediumswift
strings in the repo to the name of your app and make related changes in Info.plist
and App Delegate
files. The deployment with Heroku is easy - just link your GitHub repo and the app is built automatically.
You are all set!
MediumSDKManager
class is designed as a singleton, you can access all it’s methods by calling a shared instance:
let mediumSession = MediumSDKManager.sharedInstance
List of methods of the MediumSDKManager
class:
doOAuthMedium(completionHandler: (String, String) -> Void)
checkCred(completionHandler: (String, String) -> Void)
getUserID(completionHandler: (String, String) -> Void)
getToken(completionHandler: (String, String) -> Void)
signOutMedium(completionHandler: (String, String) -> Void)
ownCredentialsRequest(completionHandler: (String, String) -> Void)
userPublicationsListRequest(completionHandler: (String, String, JSON) -> Void)
getListOfContributors(publicationId: String, completionHandler: (String, String, JSON) -> Void)
createPost(title: String, contentFormat: String, content: String, canonicalUrl: String?=nil, tags: [String]?=nil, publishStatus: MediumPublishStatus?=nil, license: MediumLicense?=nil, completionHandler: (String, String) -> Void)
createPostUnderPublication(rootPublication: String, title: String, contentFormat: String, content: String, canonicalUrl: String?=nil, tags: [String]?=nil, publishStatus: MediumPublishStatus?=nil, license: MediumLicense?=nil, completionHandler: (String, String) -> Void)
Note that publish status and licence fields are coded as enums with all the possible states of these parameters, when creating a publication just use the proper values.
We would love for you to contribute to Medium SDK - Swift, check the LICENSE
file for more info.
Original author: Alexander Telegin – @drinkius – [email protected]
Contributions by
Created as a part of development internship, distributed under the MIT license. See LICENSE
for more information.