The ContactsManager SDK provides a powerful invite system that enables controlled app growth, user acquisition tracking, and viral loop implementation. The invite service supports multiple distribution methods and provides detailed analytics for measuring growth effectiveness.
Retrieve the user’s current invite code, or create one if none exists:
Copy
let inviteCode = await cm.invites.codeif let code = inviteCode { print("Your invite code: \(code)") // Display code to user for sharing} else { print("Unable to get invite code")}
Retrieve the full invite URL for web-based sharing:
Copy
let inviteLink = await cm.invites.linkif let link = inviteLink { print("Share this link: \(link)") // Use link for social sharing, email, etc.} else { print("Unable to get invite link")}
Get the number of invites the current user has left:
Copy
let remaining = await cm.invites.remaining()print("You have \(remaining) invites remaining")// Use this to show invite limits in UIif remaining > 0 { // Show invite button} else { // Show "no invites left" message}
Retrieve the list of users invited by the current user:
Copy
let invitedUsers = await cm.invites.invited()print("You've invited \(invitedUsers.count) users:")for user in invitedUsers { print("- \(user.displayName ?? "Unknown")")}// Use for showing invite success and building social proof
Get information about who invited the current user:
Copy
let inviter = await cm.invites.invitedBy()if let whoInvitedMe = inviter { print("You were invited by: \(whoInvitedMe.displayName ?? "Unknown")") // Show connection to inviter in onboarding // Enable features that connect inviter and invitee} else { print("You joined without an invite")}
// Get contacts to invite (from recommendations or user selection)let contactsToInvite = await cm.people.fetch( matching: [.suggestedInvite], limit: 10)let emailBody = """Hi there!I've been using this amazing app and thought you'd love it too. It's helped me stay organized and connect with friends.Join me and let's explore it together!Best,[Your name]"""let result = await cm.invites.sendBulkInviteEmails( contacts: contactsToInvite, emailBody: emailBody)if let response = result { if response.success { print("Sent \(response.emailsSent) invites successfully") if !response.failedEmails.isEmpty { print("Failed to send to: \(response.failedEmails.joined(separator: ", "))") } } else { print("Email invite failed: \(response.message)") }}