Iphone ABUnknownPersonViewController using allowsAddingToAddressBook = YES issue - iphone

Let me explain what i want to do first. In native Iphone in the Recents tab if you click on a contact not found in any addressbook you have an option to "Add to Existing Contact"
After clicking on "Add to Existing Contact", a picker shows up and you make a selection. Afterwards it brings you to a ABPersonViewController automatically and allows you to edit or save the new contact:
I am trying to recreate this but having some issues. In my version, After I create the UnknownPersonViewController and the end user presses "Add to Existing Contact" a picker shows up and allows for selecting from the addressbook similar to native Iphone. But after making a selection the name gets automatically added to the addressbook and no personViewController appears to give the user a choice to add the contact or not. Even if i could just get it to not auto write to the addressbook after making a selection i could just have it show a personviewcontroller in edit mode right away.
So my issue is why is it automatically updating the addressbook after making a selection?
Im pushing the ABUnknownpersonviewcontroller onto a UITableviewController navigationcontroller. and im testing on a physical device with iOS 6.01
Here is some code:
ABRecordRef person = ABPersonCreate ();
ABMutableMultiValueRef multiValue = ABMultiValueCreateMutable(kABStringPropertyType);
ABMultiValueAddValueAndLabel(multiValue, call.number, kABPersonPhoneMainLabel,
NULL);
ABRecordSetValue(person, kABPersonPhoneProperty, multiValue, error);
if(multiValue) CFRelease(multiValue);
ABUnknownPersonViewController *unknownCtrl = [[ABUnknownPersonViewController alloc] init];
unknownCtrl.displayedPerson = person; //this has a phone number with "main" label
unknownCtrl.allowsActions = YES;
unknownCtrl.allowsAddingToAddressBook = YES;
unknownCtrl.editing=NO;
unknownCtrl.unknownPersonViewDelegate = self;
// unknownCtrl.addressBook=ABAddressBookCreate(); // I tried setting addressbook to nil and object
unknownCtrl.addressBook=nil;
[self setTitle:call.type forUIViewController:unknownCtrl];
[self.navigationController pushViewController:unknownCtrl animated:YES];
note: i have a similar problem to this post : http://forums.macrumors.com/archive/index.php/t-1023140.html
and perhaps https://discussions.apple.com/thread/1682620?start=0&tstart=0
UPDATE: it seems if i put the kABPersonPhoneMainLabel from the person, then it does not write the phone number to the contact. Aftewards what i did was in didResolveToPerson delegate i call the personviewcontroller in edit mode. This simulates the native behavior. This may answer my own question, thanks everyone.

ABUnknownPersonViewController doesn't expose many customization options, you need to implement your own version. It's not too hard though - the "Create New Contact" button just launches an ABNewPersonViewController, and the "Add to Existing Contact" launches an ABPeoplePickerNavigationController. Your ViewController should act as the delegates for those objects and controls what happens when they are completed.

Related

How to Open Addressbook New Contact Screen

In my application I have UIBarButtonSystemItemAdd on right side of the navigation controller. On tapping of that plus icon I want to open address book in editable mode. Please refer the following image.
How to open address book UI for new contact in editable mode directly?
In the AddressBookUI.framework, there is a class called ABNewPersonViewController. Basically, what you want to do is this:
ABNewPersonViewController *abnpvc = [[ABNewPersonViewController alloc] init];
[abnpvc setNewPersonViewDelegate: self];
[self presentViewController: abnpvc animated: YES completion: nil];
This brings up the view you are looking for.

How to develop a SMS client for iOS?

my original title was How to customize TTMessageController for SMS transmission?. I changed this now because I look for any possible solution and not only those with TTMessageController.
Well, I am working on an simple application in xcode4. The user should be able to send SMS from different SMS gateways.
The background logic is quite simple because everything is managed by executing some http requests on an rest api.
The hard thing for me now is to setup the UI and that is where I need help because I am new to iOS development. This is how I want it to be:
http://img222.imageshack.us/img222/3159/bhrfe.png
There should be a recipient picker to either do autosearch on contacts or to directly pick a contact from the contact list. Beside I want only one recipient. And there should be a text area.
I also want to have a label somewhere at the bottom to show the current char number.
Since I did not find those UI elements in xcode4 library I searched for something similar and I found the TTMessageController which gives me the view you see in the picture.
However plus button does not work and I am not sure how to extend all this to do what I want.
I appreciate any idea on this.
For the + Button you can use the address book UI:
// This Code is taken from Apple's sample code QuickContacts
#import <AddressBookUI/AddressBookUI.h>
-(void)showPeoplePickerController {
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
// Display only a person's phone, email, and birthdate
NSArray *displayedItems = [NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonPhoneProperty]];
picker.displayedProperties = displayedItems;
// Show the picker
[self presentModalViewController:picker animated:YES];
[picker release];
}
The <ABPeoplePickerNavigationControllerDelegate> delegate include this methods:
– peoplePickerNavigationController:shouldContinueAfterSelectingPerson:
– peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier:
– peoplePickerNavigationControllerDidCancel:
After selecting a person you can save his/her number in an array and in the text field (e.g. comma separated)
.
For the question if it will be approved here is the guideline:
https://developer.apple.com/appstore/resources/approval/guidelines.html
22.6 Apps that enable anonymous or prank phone calls or SMS/MMS messaging will be rejected
You can't use TTMessageController to send sms. The only possible way to send sms is to use MFMessageComposeViewController. Here's a tutorial on how to use it: http://blog.mugunthkumar.com/coding/iphone-tutorial-how-to-send-in-app-sms/

iOS4 ABNewPersonViewController Loses Data Entered when attempting to add a Photo iPhone 4

I have implemented a basic add contact feature to an iOS 4 application. Following the documentation from Apple, I have created a navigation controller, and set its root view to the ABNewPersonViewController. I have implemented the delegate as well. The basic mechanics all work.
The problem I am having is when you add a photo to the new person that is very large (taking a photo or picking one from the library), the ABNewPersonViewController form returns empty when the camera controls are dismissed. No photo is in the add photo box either. If I pick a small image (say a screenshot from the iPhone), everything works. I can see from the debug output: Received memory warning. Level=1
Has anyone else run into this? Is there a way to set the photo quality to a lower setting for the ABNewPersonViewController? Any help appreciated.
ABNewPersonViewController *abNewPersonView = [[ABNewPersonViewController alloc] init];
abNewPersonView.newPersonViewDelegate = self;
UINavigationController *newNavigationController = [UINavigationController alloc];
[newNavigationController initWithRootViewController:abNewPersonView];
[self presentModalViewController:newNavigationController animated:YES];
[abNewPersonView release];
[newNavigationController release];
If ABNewPersonViewController does not handle memory warnings correctly, file a bug with apple.

disable add fields option while editing contacts in iphone

I have a query regarding AddressBookUI
ABPersonViewController *personController=[[ABPersonViewController alloc] init];
ABAddressBookRef addressBook=ABAddressBookCreate();
//ABRecordRef aRecord=ABAddressBookGetPersonWithRecordID(addressBook, 25);
personController.displayedPerson=ABAddressBookGetPersonWithRecordID(addressBook, uniqueID);
personController.addressBook=addressBook;
personController.personViewDelegate=self;
personController.allowsEditing=YES;
[[self navigationController] pushViewController:personController animated:YES];
[personController release];
to show cotacts corresponding to a uniqueID
but when the view appears and I press the edit button
add fields option Appear, I want to hide this option.
Can this be done?????
If yes kindly suggest me some work around.
Thnx in advance.
That is how the standard Edit Contact view works.
You could write your own view&controller that reads the contacts values, puts them in input fields, and after the user has edited them, saves the contact. But that is quite a lot of work, and I would recomment that you use the standard View anyway.
In my opinion, it is better to use standard GUI elements as much as possible.

How to navigate back to previous view after sending sms is done in iphone?

I am new to iphone development, i have created sms application using "Text Links(sms:) and i have created the action sheets and the buttons for email, sms. On clicking sms it navigates to the another view(UIView controller) and i wrote a code for SMS.And i faced some problem ,its not removed the view properly, it doesnt goes to the previous webview properly,(Action sheets loaded in webview)
Here my code and explanation,
I have created the custom send button programmatically for sending the sms.
I am getting phone numbers in a textfield and stores it to one string(phone) and i display the article title on the label, it worked dynamically.
now i want to share the article title through sms. and i have one problem, (ie)if i click send button it should go to the previous view(webview) but it display another view.. so i want to go to the previous page properly ,when i clicked the send button.
And i also want to display the address book(Eg,default address book in the device) in my sms view page.Please guide me.
-(void) sendbtnclk
{
self.String = txtfield.text;
NSString *phone = String;
NSString *arttitle = articleTitle;
NSString *sms = [NSString stringWithFormat:#"sms:%# %#",phone,arttitle];
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:sms]];
[self.view removeFromSuperview];
}
thanks,
please help me out.
I think that when you use the openURL: method, the Text app is launched on the phone and thus the current app is dismissed.
Here is the relevant documentation.