KPS-iOS 0.5.0

KPS-iOS 0.5.0

mingshingangelc 维护。



 
依赖
Moya~> 14.0
Toast-Swift~> 5.0.1
SnapKit~> 5.0.0
DeviceKit~> 4.0
Kingfisher~> 7.0
SwiftRichString~> 3.7.2
 

KPS-iOS 0.5.0

  • 作者:
  • mingshing

KPS-iOS

KPS iOS SDK

API

设置

初始化

初始化 KPS SDK。在调用任何 KPS API 之前,请�始化 SDK,最好是在应用启动时。

//init function

用户

登录

登录 KPS 用户并与 KPS 服务器建立会话

fun KPS.login(keyId: String, token: String, callback: (errMsg: String?, kpsUser: KPSUser?, isNew: Boolean) -> Unit)
  • keyId:为签名 jwt 令牌而用的密钥 ID
  • token:由 keyId 的私钥签名的包含用户信息的 jwt 令牌

返回

  • errMsg:错误信息。如果一切正常则为空
  • kpsUser:登录的用户
  • isNew:指示当前登录的用户是新创建的还是已有的

注销

注销 KPS 用户并清除会话

fun KPS.logout(callback: (errMsg: String?) -> Unit)

返回

  • errMsg:错误信息。如果一切正常则为空

检查登录状态

检查当前用户的登录状态

fun KPS.isLoggedIn(): Boolean

返回:函数返回用户是否已登录。

注意:该结果只反映本地状态,如果会话已被远程取消,则可能不准确


内容

获取内容列表

检索内容

fun KPS.openKPSContent(contentId: String?, callback: (errMsg: String?, kpsContent: KPSContent?, children: List<KPSContent>?, orderChildrenIncreaseRight: Boolean) -> Unit)
  • ContentId:要检索的内容的 ID。对根子项输入 null。

返回

  • errMsg:错误信息。如果一切正常则为空
  • kpsContent:请求的内容
  • children:返回内容的孩子内容
  • orderChildrenIncreaseRight:指示子内容是应从左到右还是从右到左排列。

UI

显示内容列表视图

打开一个新活动来显示默认内容列表视图

fun KPS.openKPSContentUI(activity: Activity, id: String?)
  • activity:用于监听 onActivityResult 回调的当前活动
  • id:要打开的内容的 ID。对根子项输入 null。

显示文章视图

打开一个新活动来显示文章视图

fun KPS.openKPSArticleUI(activity: Activity, folderId: String, selectedAid: String) {
  • activity:用于监听 onActivityResult 回调的当前活动
  • folderId:打开文章的父文件夹 ID。对根文件夹输入 null。
  • selectedAid:打开文章的 ID。

模型

用户

KPSUser

data class KPSUser {
    public val id: String
}
  • id:唯一的用户 ID

内容

KPSContent

data class KPSContent {
    public val id: String,
    public val type: String,
    public val name: String,
    public val description: String,
    public val customData: JSONObject?,
    public val images: ArrayList<KPSImageResource>
}
  • id:内容 ID
  • type:内容类型,可用于确定要使用的 UI
  • name:内容名称
  • description:内容描述
  • images:内容图片
  • customData:来自发布中的特殊自定义数据,如果有。

KPSImage

data class KPSImage {
    public val width: Int,
    public val height: Int,
    fun getUri(targetWidth: Int): String
}
  • width:原始图像宽度
  • height:原始图像高度
  • getUri:一个返回目标宽度的缩略图的 uri 的方法