react-native-select-contact
react-native-select-contact copied to clipboard
Cannot selectContactPhone on iOS
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 , for me, it works for first time but when i try for a second time ,it doesn't response. any solution yet.
It says cannot open the contact selector twice
, what's that about?
@codenaz it works for me when i put the above code inside onPress Function itself of TouchableOpacity (put it alone), NOT calling another function
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
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?
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.
Not working
Error: Cannot open the contact selector twice
Try downgrading react-native-select-contact to 1.5.0 in package.json and run npm install and pod install in ios directory
@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.
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
i face this on Android Error: Cannot open the contact selector twice
i face this on Android Error: Cannot open the contact selector twice
I have the same thing on android 11
i found the solution. Add this to Android Manifest. And it worked like a charm on Android 11. Try this.
@thanhluantl2304 thank you for your help but i did try that and it did not work for me
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];
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 please show us the changes that you made