stream-swift 是一个用于 Stream 的 Swift 客户端。
您可以在 https://getstream.io/get_started 注册 Stream 账户。
Feeds 集成包括服务端和客户端代码的组合,并且接口可能差异很大,这就是我们不再专注于支持此 SDK 的原因。如果您是从头开始,我们建议您仅使用服务端 SDK。
这绝不反映我们维护和改进 Feeds API 的承诺,Feeds API 将永远是我们支持的产品。
如果您想改进此 SDK,我们仍然欢迎来自社区成员的 Pull Request。
对于 Stream,请在您的 Podfile
中使用以下条目
用于 Swift 5
pod 'GetStream', '~> 2.0'
用于 Swift 4.2
pod 'GetStream', '~> 1.0'
然后运行 pod install
。
在任何您想使用 Stream 的文件中,不要忘记使用 import GetStream
导入框架。
要使用 Apple 的 Swift 包管理器进行集成,请将以下内容作为依赖项添加到您的 Package.swift
中
.package(url: "https://github.com/GetStream/stream-swift.git", .upToNextMajor(from: "1.0.0"))
在您的 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 示例请见此处
版权所有 (c) 2016-2018 Stream.io Inc 和各个贡献者。保留所有权利。
有关本软件的历史记录、使用条款和条件以及免责声明,请参阅文件“LICENSE”。