Skip to main content
Expires all entitlements for the currently identified user while preserving their user ID and attributes. This is a convenience method designed for testing and development environments to simulate entitlement expiry and test offer flows repeatedly for the same user.
Unlike reset() which clears everything, revokeEntitlements() only expires entitlements - the user remains identified with their attributes intact. This allows you to test multiple offer cycles for the same user.

Signature

@discardableResult
public func revokeEntitlements() async throws -> Void

Returns

Returns Void on success. Throws EncoreError on failure.

Usage

Complete Testing Lifecycle for a User

Test the full entitlement lifecycle from offer presentation through expiry and re-testing for the same user:
func testCompleteEntitlementLifecycle() async {
  // User identity is preserved throughout this entire flow
  Encore.shared.identify(userId: "test_user_123")
  
  // 1. Verify no active entitlements at start
  let hasTrialInitially = await Encore.shared.isActive(.freeTrial())
  print("Has trial initially: \(hasTrialInitially)") // false
  
  // 2. Present offer and grant entitlement
  do {
    let result = try await Encore.placement("test_flow").show()
    switch result {
    case .granted(let entitlement):
      print("✅ User accepted offer: \(entitlement)")
      
      // 3. Verify entitlement is now active
      let hasTrialAfterGrant = await Encore.shared.isActive(.freeTrial())
      print("Has trial after grant: \(hasTrialAfterGrant)") // true
      
    case .notGranted(let reason):
      print("User declined: \(reason)")
      return
    }
  } catch {
    print("Error presenting offer: \(error)")
    return
  }
  
  // 4. Simulate entitlement expiry using revokeEntitlements
  //    Note: User identity (test_user_123) is preserved
  do {
    try await Encore.shared.revokeEntitlements()
    print("✅ Entitlements expired - user still identified as test_user_123")
    
    // 5. Verify entitlement is no longer active
    let hasTrialAfterRevoke = await Encore.shared.isActive(.freeTrial())
    print("Has trial after revoke: \(hasTrialAfterRevoke)") // false
    
    // Ready to test another offer cycle for the same user
    print("User ID: \(Encore.shared.currentUserId)") // Still "test_user_123"
  } catch {
    print("❌ Failed to revoke: \(error)")
  }
}

Testing with Universal Sandbox Key

Combine revokeEntitlements() with the universal sandbox key to test multiple offer cycles for the same user from any location:
#if DEBUG
// Configure with sandbox key to bypass geo-filtering
Encore.shared.configure(
  apiKey: "enc_pub_sandbox...",
  logLevel: .debug
)

Encore.shared.identify(userId: "test_user_456")

// 1. Present offer and test acceptance flow
Encore.placement("test_offer").show()

// 2. Later: Expire entitlements to test another cycle for the same user
try await Encore.shared.revokeEntitlements()
// User test_user_456 is still identified, just has no active entitlements now

// 3. Present offer again to the same user
Encore.placement("test_offer_2").show()
#endif
The combination of universal sandbox key (configure()) and revokeEntitlements() allows you to test multiple offer cycles for the same user from any location without geo-filtering restrictions.
  • configure() - Configure SDK with admin API key
  • isActive() - Check entitlement status after revoking
  • reset() - Clear user session and entitlements
  • identify() - Set user ID for testing specific users