react-native-select-contact icon indicating copy to clipboard operation
react-native-select-contact copied to clipboard

Cannot selectContactPhone on iOS

Open MariuszSpeednet opened this issue 5 years ago • 17 comments

When using "selectContactPhone" nothing happens.

Code:

selectContactPhone()
      .then(selection => {
        if (!selection) {
          return null;
        }

        let { contact, selectedPhone } = selection;
        console.log(`Selected ${selectedPhone.type} phone number ${selectedPhone.number} from ${contact.name}`);
        return selectedPhone.number;
      });

Logs:

[reports] Main Thread Checker: UI API called on a background thread: -[UIWindow rootViewController] PID: 450, TID: 136063, Thread name: (none), Queue name: com.facebook.react.SelectContactQueue, QoS: 0 [Assert] Cannot be called with asCopy = NO on non-main thread. [Assert] Cannot be called with asCopy = NO on non-main thread. Warning: Attempt to present <CNContactPickerViewController: 0x1038f5730> on <RNNStackController: 0x104005000> whose view is not in the window hierarchy!

Using RN version 0.60.4 and react-native-navigation 4.0.8

MariuszSpeednet avatar Dec 30 '19 15:12 MariuszSpeednet

@MariuszSpeednet , for me, it works for first time but when i try for a second time ,it doesn't response. any solution yet.

yehiaemad avatar Apr 14 '20 20:04 yehiaemad

It says cannot open the contact selector twice, what's that about?

codenaz avatar May 26 '20 04:05 codenaz

@codenaz it works for me when i put the above code inside onPress Function itself of TouchableOpacity (put it alone), NOT calling another function

yehiaemad avatar May 27 '20 19:05 yehiaemad

Same here.

Instead of react-native Modal component, modal behavior of wix/react-native-navigation (RNN) can open multi-layer modals.

This lib's iOS Contacts app can open on top of one modal layer for now: https://github.com/streem/react-native-select-contact/blob/5a857e3ddda0513f0b49731d7820bca62d2dc59c/ios/RCTSelectContact/RCTSelectContact.m#L28-L35

I propose to integrate this RNN workaround: https://github.com/wix/react-native-navigation/blob/c7509c52fab7142b2bffc5b851747ef14b595ef1/lib/ios/RNNModalManager.m#L147-L150

I think it will work without RNN too

oxyii avatar Jun 30 '20 16:06 oxyii

It's still not showing on iOS, on calling the function once nothing happens and on the second time it gives error - "cannot open the contact selector twice".

Can anybody help me with this?

namantayal avatar Apr 17 '21 07:04 namantayal

So after a lot of searching, I found the solution. I was using a modal and closing that modal at the time of opening the contact list, that was the mistake. What IOS does is, links the native UI screen with the last app screen and in my case, it was that modal screen. As that modal screen is no more present, IOS wasn't able to show that native UI screen. The solution was pretty simple, I close the modal after the user interaction.

namantayal avatar Apr 18 '21 14:04 namantayal

Not working

Error: Cannot open the contact selector twice

manawaraquevix avatar Jun 03 '21 04:06 manawaraquevix

Try downgrading react-native-select-contact to 1.5.0 in package.json and run npm install and pod install in ios directory

HLeshan avatar Jun 16 '21 20:06 HLeshan

@manawaraquevix @HLeshan You see this error, even on the first opening of the modal? I wouldn't expect 1.6 to have introduced any changes in this regard, so curious if 1.5 is working well for you.

seanadkinson avatar Jun 16 '21 20:06 seanadkinson

When I was start using this library I was on 1.5 and it was working fine by the time but after those new updates some how I started to get this same error and I tried downgrading it again it to 1.5 and its started working

HLeshan avatar Jun 17 '21 00:06 HLeshan

i face this on Android Error: Cannot open the contact selector twice

thanhluantl2304 avatar Sep 06 '21 06:09 thanhluantl2304

i face this on Android Error: Cannot open the contact selector twice

I have the same thing on android 11

bellalzohir avatar Sep 27 '21 07:09 bellalzohir

i found the solution. Add this to Android Manifest. And it worked like a charm on Android 11. Try this. Screen Shot 2021-09-27 at 14 24 40

thanhluantl2304 avatar Sep 27 '21 07:09 thanhluantl2304

@thanhluantl2304 thank you for your help but i did try that and it did not work for me

bellalzohir avatar Sep 27 '21 17:09 bellalzohir

The below changes worked for me.

Comment out the below lines at below file path

Path: YOUR_PROJECT/node_modules/react-native-select-contactios/RCTSelectContact/RCTSelectContact.m

Existing code:

// Launch Contact Picker UIViewController *root = [[[UIApplication sharedApplication] delegate] window].rootViewController; while(root.presentedViewController) { root = root.presentedViewController; } [root presentViewController:picker animated:YES completion:nil];

Apply changes as below:

UIViewController *root = [[[UIApplication sharedApplication] delegate] window].rootViewController; // while(root.presentedViewController) { // root = root.presentedViewController; // } [root presentViewController:picker animated:YES completion:nil];

VikkiAhuja avatar Nov 12 '21 07:11 VikkiAhuja

So after a lot of searching, I found the solution. I was using a modal and closing that modal at the time of opening the contact list, that was the mistake. What IOS does is, links the native UI screen with the last app screen and in my case, it was that modal screen. As that modal screen is no more present, IOS wasn't able to show that native UI screen. The solution was pretty simple, I close the modal after the user interaction.

Thanks! only after i received the phone I closed the popup and it work great

jeffreybenabou avatar Aug 30 '22 10:08 jeffreybenabou

@jeffreybenabou please show us the changes that you made

bilal-prog avatar Apr 20 '23 13:04 bilal-prog