Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[expo-contacts] GetContactsAsync crash on ios #29224

Closed
amitshabo opened this issue May 31, 2024 · 20 comments
Closed

[expo-contacts] GetContactsAsync crash on ios #29224

amitshabo opened this issue May 31, 2024 · 20 comments
Assignees
Labels
needs review Issue is ready to be reviewed by a maintainer

Comments

@amitshabo
Copy link

Minimal reproducible example

https://github.com/expo/expo

What platform(s) does this occur on?

iOS

Did you reproduce this issue in a development build?

No (tested in Expo Go)

Summary

since i upgraded to expo 51 the expo-contacts libary is crashing on ios when im calling the function getContactsAsync with phoneNumbers / email (that what i tried).

  useEffect(() => {
    const fetchContacts = async () => {
      try {
        const { status } = await Contacts.requestPermissionsAsync();
        if (status === 'granted') {
          const { data } = await Contacts.getContactsAsync({
            fields: [Contacts.Fields.PhoneNumbers],
          });

          if (data.length > 0) {
            setContacts(data);
          }
        } else {
          setError('Permission to access contacts was denied');
        }
      } catch (err) {
        console.error('Failed to fetch contacts:', err);
        setError('Failed to fetch contacts');
      }
    };

    fetchContacts();
  }, []);

Environment

System:
OS: macOS 14.5
Shell: 3.2.57 - /bin/sh
Binaries:
Node: 20.10.0 - /usr/local/bin/node
npm: 10.8.0 - /usr/local/bin/npm
SDKs:
iOS SDK:
Platforms: DriverKit 23.0, iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0
IDEs:
Android Studio: 2022.3 AI-223.8836.35.2231.11090377
Xcode: 15.0.1/15A507 - /usr/bin/xcodebuild
npmPackages:
@expo/metro-config: ~0.18.1 => 0.18.3
expo: ~51.0.9 => 51.0.9
react: 18.2.0 => 18.2.0
react-native: 0.74.1 => 0.74.1
npmGlobalPackages:
eas-cli: 9.1.0
expo-cli: 6.3.10
Expo Workflow: bare

Expo Doctor Diagnostics

✔ Check Expo config for common issues
✔ Check package.json for common issues
✔ Check native tooling versions
✔ Check dependencies for packages that should not be installed directly
✔ Check for common project setup issues
✔ Check npm/ yarn versions
✔ Check for issues with metro config
✔ Check for legacy global CLI installed locally
✔ Check that native modules do not use incompatible support packages
✔ Check Expo config (app.json/ app.config.js) schema
✔ Check that native modules use compatible support package versions for installed Expo SDK
✔ Check that packages match versions required by installed Expo SDK

Didn't find any issues with the project!

@amitshabo amitshabo added the needs validation Issue needs to be validated label May 31, 2024
@expo-bot expo-bot added needs review Issue is ready to be reviewed by a maintainer and removed needs validation Issue needs to be validated labels May 31, 2024
@ChristopherGabba
Copy link

ChristopherGabba commented May 31, 2024

I'm also experiencing this bug for some users.

Sentry capturing this:
Screenshot 2024-05-31 at 8 27 44 AM

@savkevip
Copy link

savkevip commented Jun 3, 2024

Same here :/

@ChristopherGabba
Copy link

I will spend some time debugging this in the evening today. It happens for one user but not the other with the same code, so I suspect it may be related to a specific contact or something in a weird format causing the crash. Will post details after.

@ChristopherGabba
Copy link

ChristopherGabba commented Jun 4, 2024

Okay I ruled it down to the line of code:

    const { data } = await Contacts.getContactsAsync({
      fields: [
        Contacts.Fields.ID,
        Contacts.Fields.Name,
        Contacts.Fields.PhoneNumbers,
        Contacts.Fields.Image,
        Contacts.Fields.ImageAvailable,
      ],
    })

Device Info:

  • iOS 17.4.1
  • iPhone 13
  • expo-contacts 13.0.3

I downgraded our app to expo-contacts 12.8.2 and the bug disappeared and it no longer crashes.

@Gutistavo
Copy link

Guys, this freezing issue occurs when a contact in the iPhone has the department field filled. Unfortunately, it hasn't been fixed yet, but to manually correct it, do this:

Access the file:
/node_modules/expo-contacts/ios/Serialization.swift

Change the following line:

   if fieldHasValue(field: person.departmentName) {
-    contact[ContactsKey.department] = person.dates
+    contact[ContactsKey.department] = person.departmentName
   }

Finally, go to the root of your project and run the command to create the correction patch:

npx patch-package expo-contacts

@ChristopherGabba
Copy link

@Gutistavo Seems like a really obvious and easy to fix bug. We shall see how long it takes for them to fix...

@gabrieldonadel
Copy link
Member

This issue was actually fixed here a few weeks ago #28968. I just cherry-picked the commit with the fix to our SDK 51 branch and a new version of expo-contacts will be available soon.

@amitshabo
Copy link
Author

Still crashing on expo-contacts 13.0.4, i dont think the department name is the only problem.. i tried also with npx patch-package before the publish and still crash.
any suggestions?

@gabrieldonadel
Copy link
Member

Hi @amitshabo, the fix for this will go into expo go in the next build that we do in the coming weeks. In dev builds/release builds, you can install expo-contacts@13.0.4 today for the fix

@amitshabo
Copy link
Author

Hi @gabrieldonadel , Im currently on dev, installed the expo-contacts@13.0.4, still crashes. you sure the department was the only problem?

@gabrieldonadel
Copy link
Member

If you're running a development build can you share the error given by Xcode when the app crashes?

@ChristopherGabba
Copy link

@amitshabo You may need to recompile a new development build for the new version to go live. This did it for me.

@savkevip
Copy link

savkevip commented Jun 17, 2024

Guys, this freezing issue occurs when a contact in the iPhone has the department field filled. Unfortunately, it hasn't been fixed yet, but to manually correct it, do this:

Access the file: /node_modules/expo-contacts/ios/Serialization.swift

Change the following line:

   if fieldHasValue(field: person.departmentName) {
-    contact[ContactsKey.department] = person.dates
+    contact[ContactsKey.department] = person.departmentName
   }

Finally, go to the root of your project and run the command to create the correction patch:

npx patch-package expo-contacts

I have still the error even I see this is fixed in 13.0.4 - > node_modules... I tried to downgrade the version but nothing helped... getContactsAsync working only if I dont send any arguments but there are no names which I need... only solution is maybe to return to SDK 50?

@gabrieldonadel
Copy link
Member

@savkevip If you're running a development build and not using Expo Go, can you share the error given by Xcode when the app crashes?

@savkevip
Copy link

@savkevip If you're running a development build and not using Expo Go, can you share the error given by Xcode when the app crashes?

so when I run npx expo run:ios --device on the device everything is ok when I run over the QR code just crashes without error (no error in the console just the app closes) and when I try to run it on Xcode is crashing on the build.

@ChristopherGabba
Copy link

@savkevip I think if you are using expo-dev build you need to rebuild your development client with the updated 13.0.4 version.

@jay-stance
Copy link

I still face the same problem with the expo-contacts library crashing on iOS. I've tried all the suggested fixes, but nothing has worked.

@amitshabo
Copy link
Author

I still face the same problem with the expo-contacts library crashing on iOS. I've tried all the suggested fixes, but nothing has worked.

What worked for me was in local turn it off with config and in prod / test mode enable it after build and it works perfect.
i have developed it with just requesting like 100 contacts instead of all and in prod mode i have taken all.

@jay-stance
Copy link

jay-stance commented Aug 20, 2024 via email

@amitshabo
Copy link
Author

How do you mean? Jay Stance

On Tue, 20 Aug 2024 at 7:31 AM, Amit Shabo @.> wrote: I still face the same problem with the expo-contacts library crashing on iOS. I've tried all the suggested fixes, but nothing has worked. What worked for me was in local turn it off with config and in prod / test mode enable it after build and it works perfect. i have developed it with just requesting like 100 contacts instead of all and in prod mode i have taken all. — Reply to this email directly, view it on GitHub <#29224 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQHOHR4UNWAPVOAQXRXZP2DZSLPCZAVCNFSM6AAAAABISFDK7WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJYGA3DQOBUHE . You are receiving this because you commented.Message ID: @.>

I did something like this:

     const { status } = await Contacts.requestPermissionsAsync();
        if (status === 'granted') {
          setHasContactsPermission(true);
          let fetchedContacts = [];
          let options = { fields: [Contacts.Fields.PhoneNumbers, Contacts.Fields.Image] };

          if (env === 'DEV') {
            options.pageSize = 100;
          }

          const { data } = await Contacts.getContactsAsync(options);
     if (fetchedContacts.length > 0) {
            setContacts(fetchedContacts);
          }
 }

In production it works with all the contacts. just local its still crashed for me..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review Issue is ready to be reviewed by a maintainer
Projects
None yet
Development

No branches or pull requests

7 participants