Activity collection
Set GraffityARCloudConfiguration.userId to your stable player ID to enable tap-to-collect for collectible content authored in Graffity Console. This ID also scopes user-specific content requests.
import GraffityARCloud
@MainActor
final class CollectionSession: @preconcurrency GraffityARCloudDelegate {
let sdk: GraffityARCloud
init(accessToken: String, playerId: String) throws {
sdk = try GraffityARCloud(configuration: GraffityARCloudConfiguration(
accessToken: accessToken,
mode: .arContent,
userId: playerId
))
sdk.delegate = self
}
func graffityARCloud(
_ sdk: GraffityARCloud,
didCollect contentId: String,
activity: GraffityARActivity
) {
print("Collected: \(contentId)")
print("Progress: \(activity.collectedContentIds.count)/\(activity.maxCollectionSize)")
if activity.isFinished {
// Present your app's completion UI.
print("Finished activity: \(activity.id)")
}
}
func graffityARCloud(_ sdk: GraffityARCloud, didFailWith error: GraffityARCloudError) {
print(error.localizedDescription)
}
}Retain CollectionSession and host its SDK view as in the quick start. Without userId, tap-to-collect cannot submit a player collection. Ordinary content still needs a collection effect to become collectible.
Collection result
GraffityARActivity is Sendable, Codable, and Equatable:
| Property | Type | Meaning |
|---|---|---|
id | String | Activity identifier. |
projectId | String | Project or campaign. |
playerId | String | Participating player. |
isFinished | Bool | Activity completion. |
collectedContentIds | [String] | Already collected content. |
maxCollectionSize | Int | Required collection size. |
bannerImageURL | URL? | Optional banner image. |
collectionEmptyImageURL | URL? | Optional empty-slot image. |
collectionActiveImageURL | URL? | Optional filled-slot image. |
lastModified | Date? | Last server modification. |
Use the result for your app’s progress or completion UI. Collection works with default telemetry: .disabled.