Display Contact List
Goal
Read contacts from the device and display all contact names in a UI list.
Actions Required
AddressBookReadContacts
Fetch contacts from device
AddressBookGetReadContactsSuccessResult
Get contact count for loop
AddressBookGetContactInfo
Extract individual contact details
Variables Needed
contactCount (Int)
contactIndex (Int) = 0
firstName (String)
lastName (String)
fullName (String)
phoneNumbers (Array: String) - PlayMaker Array (set element type to String)
emailAddresses (Array: String) - PlayMaker Array (set element type to String)
Implementation Steps
1. State: ReadAllContacts
Action: AddressBookReadContacts
Inputs:
limit: 0 (read all)
offset: 0
mustIncludeName: true
mustIncludePhoneNumber: false
mustIncludeEmail: false
Events:
successEvent β GetCount
failureEvent β ShowError
2. State: GetCount
Action: AddressBookGetReadContactsSuccessResult
Outputs:
contactCount β contactCount variable
Transition: Set contactIndex = 0, go to LoopStart
3. State: LoopStart
Logic: Int Compare
If contactIndex < contactCount β GetContactDetails
If contactIndex >= contactCount β Complete
4. State: GetContactDetails
Action: AddressBookGetContactInfo
Inputs:
contactIndex β contactIndex variable
Outputs:
firstName β firstName
lastName β lastName
fullName β fullName
phoneNumbers β phoneNumbers array
emailAddresses β emailAddresses array
Transition: Go to AddToList
5. State: AddToList
Add fullName (or firstName + lastName) to your UI list component.
Increment contactIndex by 1
Return to LoopStart
Loop Pattern
Common Issues
Index Out of Range: Ensure loop condition is
contactIndex < contactCount(not <=)Empty Names: Some contacts may have empty firstName/lastName; use fullName as fallback
Large Lists: For >50 contacts, consider pagination (see UseCase3)
Array Access: phoneNumbers and emailAddresses are arrays; check Length before accessing
Performance Tip
For large contact lists (100+), use pagination instead of loading all contacts at once to prevent UI freezing.
Last updated
Was this helpful?