Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
whoscall
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Wei Han
whoscall
Commits
a23600ed
Commit
a23600ed
authored
Sep 17, 2025
by
Wei Han
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
can create multiple contacts at once
parent
7dfd54fa
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
21 deletions
+47
-21
App.tsx
App.tsx
+47
-21
No files found.
App.tsx
View file @
a23600ed
...
...
@@ -118,34 +118,60 @@ export default function App() {
const
allGranted
=
Object
.
values
(
statuses
).
every
(
s
=>
s
===
RESULTS
.
GRANTED
);
// ✅ New: Function to insert contact
const
insertContact
=
async
()
=>
{
try
{
// double-check permission
const
perm
=
Platform
.
OS
===
'android'
?
await
check
(
PERMISSIONS
.
ANDROID
.
WRITE_CONTACTS
)
:
await
check
(
PERMISSIONS
.
IOS
.
CONTACTS
);
if
(
perm
!==
RESULTS
.
GRANTED
)
{
Alert
.
alert
(
"Permission Needed"
,
"Please grant contacts permission to save contacts."
);
const
createMultipleContacts
=
async
()
=>
{
try
{
// 1️⃣ Ensure permission granted
const
readPerm
=
Platform
.
OS
===
'android'
?
await
check
(
PERMISSIONS
.
ANDROID
.
READ_CONTACTS
)
:
await
check
(
PERMISSIONS
.
IOS
.
CONTACTS
);
const
writePerm
=
Platform
.
OS
===
'android'
?
await
check
(
PERMISSIONS
.
ANDROID
.
WRITE_CONTACTS
)
:
RESULTS
.
GRANTED
;
if
(
readPerm
!==
RESULTS
.
GRANTED
||
writePerm
!==
RESULTS
.
GRANTED
)
{
const
reqRead
=
Platform
.
OS
===
'android'
?
await
request
(
PERMISSIONS
.
ANDROID
.
READ_CONTACTS
)
:
await
request
(
PERMISSIONS
.
IOS
.
CONTACTS
);
const
reqWrite
=
Platform
.
OS
===
'android'
?
await
request
(
PERMISSIONS
.
ANDROID
.
WRITE_CONTACTS
)
:
RESULTS
.
GRANTED
;
if
(
reqRead
!==
RESULTS
.
GRANTED
||
reqWrite
!==
RESULTS
.
GRANTED
)
{
Alert
.
alert
(
'Permission Denied'
,
'Cannot create contacts without permission.'
);
return
;
}
}
// 2️⃣ Define your contact list
const
contactsToCreate
=
[
{
name
:
'Support Line'
,
number
:
'+60123456789'
},
{
name
:
'Sales Hotline'
,
number
:
'+60111222333'
},
{
name
:
'Emergency'
,
number
:
'+60199887766'
},
];
// 3️⃣ Loop & insert contacts
for
(
const
c
of
contactsToCreate
)
{
const
newContact
=
{
displayName
:
'Support Line'
,
givenName
:
'Support'
,
familyName
:
'Line'
,
phoneNumbers
:
[{
label
:
'mobile'
,
number
:
'+60123456789'
}],
emailAddresses
:
[{
label
:
'work'
,
email
:
'support@example.com'
}],
displayName
:
c
.
name
,
givenName
:
c
.
name
,
phoneNumbers
:
[{
label
:
'mobile'
,
number
:
c
.
number
}],
};
await
Contacts
.
addContact
(
newContact
);
Alert
.
alert
(
'✅ Success'
,
'Contact added successfully'
);
}
catch
(
error
)
{
console
.
error
(
'Failed to add contact:'
,
error
);
Alert
.
alert
(
'❌ Error'
,
String
(
error
));
try
{
await
Contacts
.
addContact
(
newContact
);
console
.
log
(
`✅ Contact added:
${
c
.
name
}
`
);
}
catch
(
err
)
{
console
.
error
(
`❌ Failed to add contact
${
c
.
name
}
:`
,
err
);
}
}
};
Alert
.
alert
(
'Done ✅'
,
`Created
${
contactsToCreate
.
length
}
contacts.`
);
}
catch
(
error
)
{
console
.
error
(
'Error creating contacts:'
,
error
);
Alert
.
alert
(
'Error'
,
String
(
error
));
}
};
const
reloadCallDirectory
=
async
()
=>
{
if
(
Platform
.
OS
!==
"ios"
||
!
CallDirectoryManager
)
return
;
...
...
@@ -180,7 +206,7 @@ export default function App() {
<
Button
title=
"Check Again"
onPress=
{
checkAllPermissions
}
/>
<
Button
title=
"➕ Add Contact"
onPress=
{
insertContact
}
/>
<
Button
title=
"➕ Add Contact"
onPress=
{
createMultipleContacts
}
/>
{
Platform
.
OS
===
"ios"
&&
(
<
Button
title=
"Reload Call Directory"
onPress=
{
reloadCallDirectory
}
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment