Closed homanp closed 8 years ago
@joshuapinter Tested this in my fork. Works well.
Nice man! I left a comment on the code to use the new getContact
method.
Also, can you update the README with a section for this method.
@joshuapinter Yeah, will do. Doing create as well. Will post a PR for that tomorrow probably
👍
Just realized I didn't make a README entry for getContact
😮 Doing that now. :)
Hmm..after thinking about it. We will use getContact
in at least three different methods. GET, UPDATE, DESTROY.
Would be nice to create a private function that handles the lookup of CNContact
and then use that in all the three different methods exposed to RN. Perhaps this applies to getAll
as well.
What are your thoughts @joshuapinter?
Good call. Can you create a private method called getCNContact
and have it take an identifier
and the keysToFetch
? That should keep it nice and clean.
And if you do that can you update getContact
to use that as well?
Ok, will do. BTW, have a question for you. Started implementing create contact. But I'm getting a breakpoint in the beginning of my function. Could you shed some light on it?
@objc func createContact(contactData: [String: AnyObject], callback: (NSObject) -> () ) -> Void {
......
}
RCT_EXTERN_METHOD(createContact:(NSDictionary *)contactData callback:(RCTResponseSenderBlock)callback);
Trace
CoreFoundation`-[NSInvocation invokeWithTarget:]:
0x1115fccf0 <+0>: pushq %rbp
0x1115fccf1 <+1>: movq %rsp, %rbp
0x1115fccf4 <+4>: pushq %r14
0x1115fccf6 <+6>: pushq %rbx
0x1115fccf7 <+7>: subq $0x10, %rsp
0x1115fccfb <+11>: movq %rdi, %rbx
0x1115fccfe <+14>: movq %rdx, -0x18(%rbp)
0x1115fcd02 <+18>: movq 0x2ab287(%rip), %rsi ; "setArgument:atIndex:"
0x1115fcd09 <+25>: movq 0x2bd4f8(%rip), %r14 ; (void *)0x0000000110fcd800: objc_msgSend
0x1115fcd10 <+32>: leaq -0x18(%rbp), %rdx
0x1115fcd14 <+36>: xorl %ecx, %ecx
0x1115fcd16 <+38>: callq *%r14
0x1115fcd19 <+41>: movq 0x2ab278(%rip), %rsi ; "invoke"
0x1115fcd20 <+48>: movq %rbx, %rdi
0x1115fcd23 <+51>: callq *%r14
0x1115fcd26 <+54>: addq $0x10, %rsp
0x1115fcd2a <+58>: popq %rbx
0x1115fcd2b <+59>: popq %r14
0x1115fcd2d <+61>: popq %rbp
0x1115fcd2e <+62>: retq
0x1115fcd2f <+63>: nop
Am I missing something?
No idea. Only thing I can think of is that your RCT_EXTERN_METHOD
uses NSDictionary
as the param where as createContact
uses [String: AnyObject]
.
So how should one pass a JS object from RN to Swift?
Not sure. Haven't done that yet. But I imagine using a NSDictionary would be the way to go (all of RN is built in Obj-C).
Take a look at this for an idea: https://github.com/rt2zz/react-native-addressbook/blob/master/RCTAddressBook.m#L208
Yeah, OK.
@joshuapinter I'm closing this PR and will post a new one which has both CREATE
and DELETE
as well as the getCNContact
utility function
@homanp Sounds good. I left a bunch of comments on the new PR #5
Added basic functionality for deleting contact.