As per my requirement,
i need to get email id's from contacts.
And i need to write a code for this in a separate class in a method.To get call this integrate classes into my project simply call that method.
This is what i need.
for this my code in ownServices is like this.
-(NSString *)getSelectedNumberFromContatcs {
ABPeoplePickerNavigationController *peoplePickerController = [[ABPeoplePickerNavigationController alloc] init];
peoplePickerController.peoplePickerDelegate = self;
[self presentModalViewController:peoplePickerController animated:NO];
[peoplePickerController release];
return aNSString;
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person {
// NSString *name = (NSString *)ABRecordCopyValue(person, kABPersonPhoneProperty);
return YES;
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier {
if (property == kABPersonPhoneProperty) {
ABMultiValueRef emails = ABRecordCopyValue(person, property);
CFStringRef phonenumberselected = ABMultiValueCopyValueAtIndex(emails, identifier);
// CFStringRef emailLabelSelected = ABMultiValueCopyLabelAtIndex(emails, identifier);
// CFStringRef emailLabelSelectedLocalized = ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(emails, identifier));
aNSString = (NSString *)phonenumberselected;
// Return to the main view controller.
[ self dismissModalViewControllerAnimated:YES ];
return NO;
}
return YES ;
}
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
[ self dismissModalViewControllerAnimated:YES ];
}
i am calling this in myclassviewcontroller like this.
- (void)viewDidLoad {
[super viewDidLoad];
ownServices *obj = [[ownServices alloc]init];
[obj getSelectedNumberFromContatcs];
}
But contatcs viewcontraoller is not opened.
But i try same code in view controller in a button action like this
-(IBAction)openContacts {
ABPeoplePickerNavigationController *peoplePickerController = [[ABPeoplePickerNavigationController alloc] init];
peoplePickerController.peoplePickerDelegate = self;
[self presentModalViewController:peoplePickerController animated:NO];
[peoplePickerController release];
}
Then contacts viewconrtroller opened.
i did n't why view controller is not opened by calling it in a method.
开发者_开发技巧is it possible to do like this.
can any one please help me.
Thank u in advance.
Because the class you are using is inherited from NSObject not UIViewController so the [self presentModalViewController:peoplePickerController animated:NO]; will not work. Also you have written this method in a wrong way
-(NSString *)getSelectedNumberFromContatcs {
ABPeoplePickerNavigationController *peoplePickerController = [[ABPeoplePickerNavigationController alloc] init];
peoplePickerController.peoplePickerDelegate = self;
[self presentModalViewController:peoplePickerController animated:NO];
[peoplePickerController release];
return aNSString;
}
Let me know what actually you want to do?
Instead of peoplePickerController.peoplePickerDelegate = self
is it possible to use the reference of your main View Controller?
精彩评论