Stream Swift 客户端
stream-swift 是 Stream 的 Swift 客户端。
您可以在 https://getstream.io/get_started 注册 Stream 账户。
安装
CocoaPods
对于 Stream,请在您的 Podfile
中添加以下条目
对于 Swift 5
pod 'GetStream', '~> 2.0'
对于 Swift 4.2
pod 'GetStream', '~> 1.0'
然后运行 pod install
。
在任何您想使用 Stream 的文件中,别忘了用 import GetStream
导入框架。
Swift Package Manager
要使用 Apple 的 Swift 包管理器进行集成,请向您的 Package.swift
添加以下依赖
.package(url: "https://github.com/GetStream/stream-swift.git", .upToNextMajor(from: "1.0.0"))
Carthage
在你的Cartfile中添加以下条目
github "GetStream/stream-swift"
然后运行carthage update
。
快速入门
// Setup a shared Stream client.
Client.config = .init(apiKey: "<#ApiKey#>", appId: "<#AppId#>", token: "<#Token#>")
// Setup a Stream current user with the userId from the Token.
Client.shared.createCurrentUser() { _ in
// Do all your requests from here. Reload feeds and etc.
}
// Create a user feed.
let userFeed = Client.shared.flatFeed(feedSlug: "user")
// Create an Activity. You can make own Activity class or struct with custom properties.
let activity = Activity(actor: User.current!, verb: "add", object: "picture:10", foreignId: "picture:10")
userFeed?.add(activity) { result in
// A result of the adding of the activity.
print(result)
}
// Create a following relationship between "timeline" feed and "user" feed:
let timelineFeed = Client.shared.flatFeed(feedSlug: "timeline")
timelineFeed?.follow(toTarget: userFeed!.feedId, activityCopyLimit: 1) { result in
print(result)
}
// Read timeline and user's post appears in the feed:
timelineFeed?.get(pagination: .limit(10)) { result in
let response = try! result.get()
print(response.results)
}
// Remove an activity by referencing it's foreignId
userFeed?.remove(foreignId: "picture:10") { result in
print(result)
}
更多API示例在此
致谢及贡献者
此仓库不再由Stream进行积极维护。
Feeds集成包括服务器端和客户端代码的组合,接口可能会有很大差异,因此我们不再专注于支持此SDK。
这绝对不是我们对维护和改进Feeds API承诺的反映,我们将始终支持这个产品。
我们继续欢迎社区成员的拉取请求。
版权及许可信息
版权(c)2016-2018 Stream.io Inc,以及个别贡献者。保留所有权利。
有关此软件的历史、使用条款和条件以及所有保证的放弃,请参阅文件“LICENSE”。