测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布最后发布 | 2016年11月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Fernando Bass 维护。
依赖 | |
OAuthSwift | ~> 1.0 |
SwiftyJSON | ~> 3.1 |
Alamofire | ~> 4.0 |
一个库,允许任何 Swift iOS 应用访问 Medium API。
pod 'MediumSDKSwift'
并在目录中运行 pod install
以加载依赖项。
将您的 MEDIUM_CLIENT_ID
, MEDIUM_CLIENT_SECRET
, MEDIUM_CALLBACK_URL
添加到 编译设置
-> 用户定义
在项目中右键单击您的 Info.plist
文件,选择“打开为” - “源代码”并添加以下行
<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>
在标签之前。
在应用代理中处理回调
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
if (url.host == "mediumswift-callback") {
OAuthSwift.handleOpenURL(url)
}
return true
}
请注意,重定向是通过免费的 Heroku 应用完成的,并强烈建议您通过克隆并运行 此存储库(感谢原始的 oauthswift.herokuapp.com 存储库)。将存储库中的所有 mediumswift
字符串更改为您的应用名称,并在 Info.plist
和 应用代理
文件中进行相关更改。在 Heroku 上部署很简单 - 只需链接您的 GitHub 仓库,应用就会自动构建。
您已设置完毕!
MediumSDKManager
类被设计成单例,您可以通过调用共享实例来访问其所有方法
let mediumSession = MediumSDKManager.sharedInstance
MediumSDKManager
类的方法列表
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)
注意,发布状态和许可字段作为枚举编码,包含这些参数的所有可能状态,创建出版物时只需使用适当的值。
我们非常欢迎您为Medium SDK - Swift贡献力量,有关更多信息,请查阅项目许可文件LICENSE
。
原作者:Alexander Telegin – @drinkius – [email protected]
贡献者包括
作为开发实习的一部分创建,按照MIT许可证分发。有关更多信息,请参阅项目许可文件LICENSE
。