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

Contacts API #686

Closed
colinramsay opened this issue Apr 5, 2015 · 19 comments
Closed

Contacts API #686

colinramsay opened this issue Apr 5, 2015 · 19 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@colinramsay
Copy link
Contributor

Doesn't look like there's anything been mentioned about a way of interfacing with the address book on a device. Is this a planned feature or something that'll be deferred to the community?

@vjeux
Copy link
Contributor

vjeux commented Apr 5, 2015

Our current thinking around all of those APIs is that it's going to be left to whoever bridges it first. If we need it internally we'll build it and dogfood it. When it becomes good and stable, we'll include it in core. But if someone else in the community beats us to it and the package on npm gains significant traction, we'll likely bring it in core instead (assuming the author wants to).

The good part is that the plugin api is public and what is being used for all the existing components today, so no one has a disadvantage.

We don't have any plans for a feature that would use the contact api right now, so it's unlikely going to be coming from us in the next few months.

This whole plugin is still very much up in the air, please let me know if you have ideas on how to make it work best for everyone

@brentvatne
Copy link
Collaborator

@colinramsay - if you're interested in building a bridge, ping me as notbrent on irc (#reactnative on freenode) and I can help you get started!

@darylrowland
Copy link
Contributor

I've started building a basic Contacts API for a project I'm working on. I'll try and pop it on Github this afternoon or tomorrow if it would be useful for people.

EDIT: the code I'm using is here: https://gist.github.com/darylrowland/62a5f12981c4669394a8

@mattotodd
Copy link

@darylrowland would love to check that out

@mattotodd
Copy link

I've begun work on this a had a few questions about the NativeModules bridge

Am I limited to String for error and params in the callbacks? What would it look like to return a object or array of objects if that is possible?

Is there a standard for what errors should return?

I realize the Native Modules are still a work in progress, but what is the expected way to package/distribute? @brentvatne showed me an example of his react-native-login which is an example xcode project that includes his actual bridge.

By the way, I was psyched out how simple it was to extend this and get it working!

Current code. Not complete, but any advice would be appreciated as I do not come from an objective-c background. (I intend to paginate the getAllContacts call, this was just to see if it was working, and it is!!)

@import AddressBook;
#import "AddressBook.h"

@implementation AddressBook

- (void)hasABAuth:(RCTResponseSenderBlock)callback  {
  RCT_EXPORT(hasAuth);
  if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusDenied ||
    ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusRestricted){
    callback(@[[NSNull null], @"denied"]);
  } else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized){
    callback(@[[NSNull null], @"authorized"]);
  } else { //ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined
    callback(@[[NSNull null], @"undetermined"]);
  }
}

- (void)requestABAuth:(RCTResponseSenderBlock)callback  {
  RCT_EXPORT(requestAuth);
  ABAddressBookRequestAccessWithCompletion(ABAddressBookCreateWithOptions(NULL, nil), ^(bool granted, CFErrorRef error) {
    if (!granted){
      callback(@[[NSNull null], @"denied"]);
      return;
    }
    callback(@[[NSNull null], @"authorized"]);
  });
}

-(void)getAllContacts:(RCTResponseSenderBlock)callback  {
  RCT_EXPORT();
  ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, nil);
  NSArray *allContacts = (__bridge NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBookRef);
  NSLog(@"%@", allContacts);
}

@end

@frantic
Copy link
Contributor

frantic commented Apr 6, 2015

Am I limited to String for error and params in the callbacks? What would it look like to return a object or array of objects if that is possible?

callback accepts array of any JSONable data, including NSArray and NSDictionary. E.g.:

callback(@[@[@1], @{@"foo": @"bar"}])

Is there a standard for what errors should return?

For passing Error-like objects, see RCTMakeError. You can attach any field to your error object, but at minimum it's good to have message.

@mattotodd
Copy link

@rt2zz
Copy link
Contributor

rt2zz commented May 5, 2015

Thanks @mattotodd

edit continuing work over @ react-native-addressbook-ios

@mattotodd
Copy link

@rt2zz replied to your issue on my repo. sorry, was out of the country this past week with little access to email, only got notified when you posted here. thx

@brentvatne
Copy link
Collaborator

Thanks @mattotodd for putting that together 😄

@niftylettuce
Copy link
Contributor

Can you please re-open this issue? We still don't have Android support.

See my bug bounty and the issue here morenoh149/react-native-contacts#10

@mattotodd
Copy link

@niftylettuce the react-native team does not build out anything they don't directly use, Contacts being one of them. If a third-party builds something and it gets good feedback, it can be pulled back in

I started an iOS version https://github.com/mattotodd/react-native-addressbook-ios

I can take a look at an Android version, but might take a little time

@niftylettuce
Copy link
Contributor

@brentvatne
Copy link
Collaborator

💅'd it @mattotodd

@mattotodd
Copy link

@brentvatne what did I nail ?

@pickhardt
Copy link

I've been using https://github.com/rt2zz/react-native-contacts but it is lacking in a number of ways, not that they aren't working on it, just that it's kind of important so I want to bring this up for discussion again. This is the sort of thing I think could really benefit by being part of official React Native, because it's pretty fundamental to a lot of apps. I'd estimate more apps would use contacts than a number of the official components (not that they're great to have too).

I propose that https://github.com/rt2zz/react-native-contacts be slated to be part of the official React Native, as a Contacts component.

@satya164
Copy link
Contributor

@pickhardt It should stay as a different module IMO. The core team won't likely to be able to work on it. So it's better to be a third party module where it can get better care.

@mattotodd
Copy link

Lets be honest, FB already knows all your contacts. They have no need to support the native contacts api, so like @satya164 said, it makes more sense for a third party to take care of it.

@niftylettuce
Copy link
Contributor

I've had a lot of success with https://github.com/axemclion/react-native-cordova-plugin (see my fork for a bug I patched), in combination with official Cordova plugins like https://github.com/apache/cordova-plugin-contacts. It's a port basically and has helped out in meanwhile.

@facebook facebook locked as resolved and limited conversation to collaborators May 31, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests