Retrieve selected group from native contact application - iphone

I am working on one application in which I need to show contacts from the contact application.
I have successfully implemented the functionality but now I need to only show the contacts from the groups which are selected in native contact application similar Magic Jack(http://itunes.apple.com/us/app/free-calls-with-magicjack/id463926997?mt=8) iPhone app.
I have tried to search on google, forums, apple's documentation but didn't able to find the solution. Can anyone help me?
I am using below code to fetch all contact information.
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef source = ABAddressBookCopyDefaultSource(addressBook);
NSArray *persons = (NSArray *)(ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, source, kABPersonSortByFirstName));

Here is code you can use,it fetch the first and last name.
-(IBAction)handlingClick:(id)sender
{
ABPeoplePickerNavigationController *peopleController = [[ABPeoplePickerNavigationController alloc] init];
peopleController.peoplePickerDelegate = self;
[self presentModalViewController:peopleController animated:YES];
[peopleController release];
}
-(void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
[peoplePicker dismissModalViewControllerAnimated:YES];
}
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier
{
return NO;
}
-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
self.firstName.text = (NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
self.lastName.text = (NSString*)ABRecordCopyValue(person, kABPersonLastNameProperty);
[self dismissModalViewControllerAnimated:YES];
return NO;
}

Is ABGroupCopyArrayOfAllMembers not suitable for what you want?

Related

Send text then call Contact iPhone App

I have an emergency call app. When the user presses on the contact it calls them. Then the user has to return to the app to send the automated SMS. However I would like it that when pressed on the contact the user is taken to the message framework and once send is pressed it then calls the person. Here is the code so far.
- (NSString *)deviceLocation {
return [NSString stringWithFormat:#"Hi, you have been contacted as there has been an emergancy. Here is the location of the caller: Latitude: %f Longitude: %f . Please call for help to that location. From Kiddy Call the iPhone app. ", locationManager.location.coordinate.latitude, locationManager.location.coordinate.longitude];
}
#pragma mark - PictureListMainTableCellDelegate methods
-(void)pictureListMainTableCell:(PictureListMainTableCell *)cell wantsToCallNumber:(NSString *)number
{
if([MFMessageComposeViewController canSendText])
{
MFMessageComposeViewController *messageComposer =
[[MFMessageComposeViewController alloc] init];
NSString *message = (#"%#", [self deviceLocation]);
[messageComposer setBody:message];
messageComposer.recipients = [NSArray arrayWithObjects:number , nil];
messageComposer.messageComposeDelegate = self;
[self presentViewController:messageComposer animated:YES completion:nil];
NSLog(#"Texting telephone number [%#]", messageComposer);
}
NSString *urlString = [NSString stringWithFormat:#"tel://%#", number];
NSLog(#"calling telephone number [%#]", number);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
NSLog(#"%#", [self deviceLocation]);
}
Any solutions to this will be greatly appreciated.
You're doing:
messageComposer.messageComposeDelegate = self;
just define:
messageComposeViewController:didFinishWithResult
It will be called when someone finished editing text and you can get result out of second parameter.
MessageComposeResultCancelled,
MessageComposeResultSent,
MessageComposeResultFailed
And from this callback you can make a call.
To make a call use:
NSString *phoneNumber = [#"telprompt://" stringByAppendingString:#"123123123"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
or tel:// for calling without prompting.

XMPPFramework not sending presence

Im developing an app for iPhone, in wich one of the functionalities is an instant message system, using XMPPFramework. By now, im testing it with Google Talk. The delegate is the same class that manages the User Interface. So, I got this code:
In viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
[self setupStream];
}
The setupStream method:
- (void) setupStream
{
NSLog(#"Inside setupStream");
xmppStream = [[XMPPStream alloc] init];
[xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
[self connect];
}
The connect method:
- (BOOL) connect
{
NSLog(#"Inside connect method");
General *general = [General sharedManager];//this is a singleton to manage settings for every user
NSString *chatid;
NSString *chatpass;
//chatid=[general user];
chatid=#"somegmailaccount#gmail.com";
xmppStream.myJID=[XMPPJID jidWithString:chatid];
if (![xmppStream isDisconnected]) {
return YES;
}
NSError *error = nil;
if (![xmppStream connect:&error])
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:[NSString stringWithFormat:#"Can't connect to server %#", [error localizedDescription]]
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alertView show];
return NO;
}
return YES;
}
In xmppStreamDidConnect method:
- (void) xmppStreamDidConnect:(XMPPStream *)sender
{
[xmppStream authenticateWithPassword:#"password" error:NULL];
[self goOnline];
}
And goOnline method:
- (void) goOnline
{
XMPPPresence *presence = [XMPPPresence presence];
[[self xmppStream] sendElement:presence];
NSLog(#"Presence sent");
}
With this, the presence is not sent. I have another google account that I try for testing (say, testing#gmail.com) and in this account the presence of somegmailaccount.gmail.com is not seen. Both accounts are connected and know each other, since I used this same accounts to develop the Android app.
Any idea about what i´m doing wrong? Any help is appreciated.
Thank you very much.
I found it! The presence is not sent this way:
XMPPPresence *presence = [XMPPPresence presence];
[[self xmppStream] sendElement:presence];
Insted, i have done it this way:
NSXMLElement *presence = [NSXMLElement elementWithName:#"presence"];
[xmppStream sendElement:presence];
This way, the presence is sent without any problem :)
With this code, i implement method xmppStreamDidAuthenticate:(XMPPStream *)sender
and the program DO enter that method without any call from my code. But if i put
[xmppStream setHostName:#"talk.google.com"];
[xmppStream setHostPort:5222];
... in method connect, the program DO NOT enter that method, nor xmppStreamDidConnect.
Im getting mad.

Custom addressbook for ABPeoplePickerNavigationController on iPhone

I am trying to create a custom addressbook on the iPhone by adding new records to the device address book (basically, merging a private contact list with the device AB). I then want to let the user select a contact, which I thought I could do with the .addressbook property of ABPeoplePickerNavigationController:
ABAddressBookRef contacts = ABAddressBookCreate();
for (PrivateUserType *user in rosterItems)
{
CFErrorRef err = NULL;
ABRecordRef ref = ABPersonCreate();
ABRecordSetValue(ref, kABPersonLastNameProperty, (CFStringRef)user.lastName, &err);
if (err != NULL)
{
NSString *errorStr = [(NSString *)CFErrorCopyDescription(err) autorelease];
NSLog(#"Can not set name: %#", errorStr);
}
...
ABAddressBookAddRecord(contacts, ref, &err);
if (err != NULL)
{
NSString *errorStr = [(NSString *)CFErrorCopyDescription(err) autorelease];
NSLog(#"Error adding XMPP roster user to addressbook: %#", errorStr);
}
}
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.addressBook = contacts;
[viewController presentModalViewController:picker animated:YES];
[picker release];
The entries are successfully added to the addressbook (which I can verify if I do an ABAddressBookSave() after the loop to add everything in). However, the entries are not shown by picker (unless I save contacts, which of course saves all changes into the device addressbook).
Is there a way to do this? This is on iOS 4.3.1.
Thanks!
As Toro said, you need save any changes to database first. ABPeoplePickerNavigationController not intended to work with uncommit data or with custom data.
You can see rather fresh topic on Apple Dev Forums
https://devforums.apple.com/message/370070#370070
where similar question was asked. And guy from Apple says that "I can't see any way to do this." But he suggest filling a bug for this to implement this feature in future release of iOS.
All you can do now is code your own UI for this AddressBook from the ground :(
updated: he-he. I found your question on App Dev Forum too )))
You need to save any changes to database by ABAddressBookSave() method.
The apple doc link.

Pretty interesting question regarding address book in iPhone

HI all i have seen the example of apple name as 'QUICK CONTACTS' and here is an error in the
person view controller. here it always show same data with two names
// Fetch the address book
ABAddressBookRef addressBook = ABAddressBookCreate();
// Search for the person named "Appleseed" in the address book
NSArray *people = (NSArray *)ABAddressBookCopyPeopleWithName(addressBook, CFSTR("Appleseed"));
// Display "Appleseed" information if found in the address book
if ((people != nil) && [people count])
{
ABRecordRef person = (ABRecordRef)[*people objectAtIndex:0*];
ABPersonViewController *picker = [[[ABPersonViewController alloc] init] autorelease];
picker.personViewDelegate = self;
picker.displayedPerson = person;
// Allow users to edit the person’s information
picker.allowsEditing = YES;
[self.navigationController pushViewController:picker animated:YES];
}
here it always show same information for two person with same name how can we remove this error.
quite confused with what you wanna ask.. if you are getting same data that means you the same data feed in two times ..are you working on a simulator ?

iphone sdk addressbook - get ABRecordRef

in the method
- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
im trying to simply access ABRecordRef as a variable, but i keep getting the error
expected expression before 'ABRecordRef'.
I can already get names and company info, but not the ABRecordRef.
What I am doing is:
NSLog(#"Contact Reference: %d", ABRecordRef);
Did you
#import <AddressBook/AddressBook.h>
? And what do you mean by
contactRef = [NSString stringWithFormat:#"%d", ABRecordRef];
? It doesn't make sense considering ABRecordRef is a type, not a number.