Insert picture image to the ABUnknownPersonViewController view in iPhone application contact page - iphone

I am working on 'About" section of my iPhone application.
I want to show some of the contributors details as a standard ABUnknownPersonViewController view.
I am creating person view using simple 'school' code:
ABRecordRef aContact = ABPersonCreate();
ABMultiValueAddValueAndLabel(email, #"John-Appleseed#mac.com", kABOtherLabel, NULL);
ABRecordSetValue(aContact, kABPersonEmailProperty, email, &anError);
ABUnknownPersonViewController *picker =[[ABUnknownPersonViewController alloc] init];
picker.displayedPerson = aContact;
picker.alternateName = person.fullName;
picker.title = [NSString stringWithFormat:#"About %#", person.firstName];
picker.message = person.message;
... and so on ....
However - I haven't found any solution how to insert person picture to the ABUnknownPersonViewController image/picture field using <AddressBook/AddressBook.h>.
Anybody knows if it is possible? I have no luck to find any snippet using google. There is plenty about multi-values examples, etc... but nothing about inserting image for a 'unknown' contact.
Hmm.. it worries me a bit
Thank You in advance for any hints.

This should work
UIImage *iconImage = [UIImage imageNamed:#"icon.png"];
NSData * data = UIImagePNGRepresentation(iconImage);
ABPersonSetImageData(aContact, (CFDataRef)data, nil);
Thats how I've done it in the past and it works. Basically create the image data and the set it for aContact.
Hope that helps

Related

How to use the existed sample application to integrate google credentials in the iphone app

From the below link I download the .zip file it contains some example. In that I played the OAuthSampleTouch application.
http://code.google.com/p/gdata-objectivec-client/downloads/list
This is the file I downloaded :
gdata-objectivec-client-1.11.0.zip
I gone through it but I am getting confusion how to pass input that is email and password and then how to connect through google form my iphone app.
Newly edited code:
This is code from OAuthSampleTouch example in the class "OAuthSampleRootViewControllerTouch.m" Please refer http://code.google.com/p/gdata-objectivec-client/downloads/list in that OAuthSampleTouch application.
- (void)signInToGoogle
{
[self signOut];
NSString *keychainAppServiceName = nil;
if ([self shouldSaveInKeychain])
{
keychainAppServiceName = kAppServiceName;
}
// For GData applications, the scope is available as
// NSString *scope = [[service class] authorizationScope];
NSString *scope = #"http://www.google.com/m8/feeds/";
// ### Important ###
// GDataOAuthViewControllerTouch is not designed to be reused. Make a new
// one each time you are going to show it.
// Display the autentication view.
GDataOAuthViewControllerTouch *viewController = [[[GDataOAuthViewControllerTouch alloc]
initWithScope:scope
language:nil
appServiceName:keychainAppServiceName
delegate:self
finishedSelector:#selector(viewController:finishedWithAuth:error:)] autorelease];
// You can set the title of the navigationItem of the controller here, if you want.
// Optional: display some html briefly before the sign-in page loads
NSString *html = #"<html><body bgcolor=silver><div align=center>Loading sign-in page...</div></body></html>";
[viewController setInitialHTMLString:html];
[[self navigationController] pushViewController:viewController animated:YES];
}
This is code from OAuthSampleTouch example in the class "OAuthSampleRootViewControllerTouch.m" Please check it. What is the scope and from where I need to pass credentials. If I run this I am getting the log as Authentication error:
Please help me, I am trying it from three days.
Any help is much appreciated.
Thank you,
Madan Mohan.
Search for this method
(GDataServiceGoogleContact *)contactService
Here you will be giving username and password for google account..

Program received signal: "EXC_BAD_ACCESS" while adding subview to main view

i am adding two labels and two image view to subview.
when ever i tap on the button i add this subview to mainview.
I am getting images from the web server and save it in local simulator documents.
NSMutableString *about_name_str = [[NSMutableString alloc]init];
[about_name_str appendString:[myDictionary objectForKey:#"firstname"]];
[about_name_str appendString:#" "];
[about_name_str appendString:[myDictionary objectForKey:#"lastname"]];
[about_name_label setText:about_name_str];
NSMutableString *about_addr_str = [[NSMutableString alloc]init];
[about_addr_str appendString:[myDictionary objectForKey:#"state"]];
[about_addr_str appendString:#","];
[about_addr_str appendString:[myDictionary objectForKey:#"country"]];
[about_addr_label setText:about_addr_str];
about_image.image = [UIImage imageWithContentsOfFile:imagepath];
about_logo.image = [UIImage imageWithContentsOfFile:logopath];
if ([myDictionary objectForKey:#"companyurl"]) {
[about_url_button setTitle:[myDictionary objectForKey:#"companyurl"] forState:UIControlStateNormal];
about_url_button.userInteractionEnabled = YES;
}
else {
about_url_button.userInteractionEnabled = NO;
}
[self.view addSubview:about_view];
this my code.
some times i got Program received signal: "EXC_BAD_ACCESS". and application quits.
i check by placing break points,and in debugger i did n't get where i am getting error.
can any one please help me,How can i resolve this.
Thank u in advance.
Try to use NSZombie.. It is a easy way to find where the EXCBADACCESS occurs...
It will specify which Method where and Which object gets deallocated(Its pretty awesome concept i like in Instruments)...
See this Link
http://www.markj.net/iphone-memory-debug-nszombie/
You should insert a breakpoint before this code is executed then step through it to find the exact line which is causing the bad access. You probably have a null or wild pointer somewhere.

Problem with pushviewcontroller animation while fetching iPhone contact's image

I am trying to show a contact from the iPhone address book. I fetch the names and image of the contacts. Then I pass these details to Detail view.
Now the problem is when I push the detail view, the animation is very slow and choppy. This happens only when I fetch the contact detail which has image. The pushviewcontroller animation works perfectly fine when the contact detail does not contain image.
Also I noticed that this problem occurs only in iPhone 4.0. When I tested this on iPhone 3gs, it worked perfectly. So I am thinking this might be device specific problem.
I fetch the contact name in the following way:
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef record=ABCFindPersonMatchingPhoneNumber(addressBook,
number, 0, 0);
if(record)
{
NSString *name=(NSString *)ABRecordCopyCompositeName(record);
NSLog(#"Contact Name %#",name);
}
And I fetch the contact image in the following way:
if (record && ABPersonHasImageData(record))
{
CFDataRef data;
data = ABPersonCopyImageData(record);
if (data)
{
NSLog(#"ImageFound");
imageData=[[NSData alloc] initWithData:(NSData *)data];
}
}
Then I pass the imageData to the Detail View
DetailView *detail=[[DetailView alloc] initWithNibName:#"DetailView" bundle:nil];
detail.imageData=imageData
[self.navigationController pushViewController:detail animated:YES];
How can I improve on this?
I know this is an old thread, but just in case if someone comes to this here with a related problem:
add
[detail view];
right after the initialization and before setting any #properties (detail.imageData=imageData;) - because the outlets of the segue are not set yet.

how to hide some properties using ABPeoplePicker

When using peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person, a view with all of the contact's information is shown. I've seen apps which only display selected info only (e.g. phone numbers).
How can I do this? I only want to display the contact's name and phone numbers.
Thank you very much!
It's pretty simple. I customized ABPeoplePickerNavigationController to only show email addresses.
The code looks like this:
ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
[peoplePicker setPeoplePickerDelegate:self];
[peoplePicker setDisplayedProperties:[NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonEmailProperty]]];
You can find a list of the available properties here.
I'm not sure if you can,
You could do this to get a list of people for the address book:
// get the default address book.
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
and then create your own custom picker view, showing only the information you want.
In Swift, you simply do this.
var people = ABPeoplePickerNavigationController()
people.peoplePickerDelegate = self
// 3 is for Phone Number
people.displayedProperties = [3]

Just how to you use TTStyledTextLabel?

All I want is to display some simple text in my viewController and have the hyperlinks autoparsed. When the user clicks on the link I want the control to somehow do a callback where I can do something with the URL. How can I achieve this?
I've already looked through the TTCatalog for hours. I have also tried looking into the source code of three20 as well as looking at the stack trace. No help. I just can't figure out how my app can react to the click of the URL. Any hints please?
Hard to help without seeing what you've already tried, but you should be able to do something like the following:
TTStyledTextLabel* label = [[[TTStyledTextLabel alloc]
initWithFrame:someFrame] autorelease];
NSString* labelText = #"This should work";
label.text = [TTStyledText textFromXHTML:labelText lineBreaks:NO URLs:YES];
[someView addSubview:label];
You can then use TTNavigator and TTURLMap to map custom-uri://some/url to a particular controller in your application, or handle it yourself in your application delegate. The best place to find out how to do that is by looking at the TTNavigatorDemo sample application included in the Three20 source. Specifically, look at AppDelegate.m which is where all the URL mapping gets performed.
In addition to what Nathan says about URL mapping and links, you can also use CSS styles!
TTStyledTextLabel* label = [[[TTStyledTextLabel alloc] initWithFrame:someFrame] autorelease];
NSString* labelText = #"This should work and
<span class=\"redText\">this should be red</span>";
label.text = [TTStyledText textFromXHTML:labelText lineBreaks:NO URLs:YES];
[someView addSubview:label];
Then in your StyleSheet.m implement
- (TTStyle*) redText {
return [TTTextStyle styleWithFont:[UIFont systemFontOfSize:12] color:RGBCOLOR(255,0,0) next:nil];
}