I'm trying to extract the phone number and email address from the address book on iOS8 and I open the person picker as follows:
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
picker.displayedProperties = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonPhoneProperty], [NSNumber numberWithInt:kABPersonEmailProperty], nil];
[self presentViewController:picker animated:YES completion:nil];
When there are multiple phone numbers and multiple email addresses in the contact details, how do I select one of each?
Ideally, I'd like to be able to tick the preferred phone and then the preferred email address but it doesn't look like I can.
Anybody know how to do this please?
Related
How would I be able to have an image show in a UIAlertView along with some text. Apparently this isn't available in iOS7, is this true? All I want is to replace some text with an image, preferably not by using custom libraries. The NSString *formula is the one I want to replace with an image.
NSString *title = [NSString stringWithFormat:#"BMI"];
NSString *mess = [NSString stringWithFormat:#"Body Mass Index, or BMI, is used by many health professionals to assess a patient's health. BMI is calculated by the formula:"];
NSString *formula = [NSString stringWithFormat:#" Weight(kg)/(Height(m)*Height(m))"];
// Combined message (mess) and Formula (formula)
NSString *combinedMess;
combinedMess = [mess stringByAppendingString:formula];
NSString *mess1 = [NSString stringWithFormat:#" Although this tool is useful in measuring a person's weight ratio, it becomes unrealiable for body builders and other extremes. BMI combined with a general indication of fitness level gives Quick Fit a clear view of the fitness level of the user."];
// Combined message (combinedMess) and message (mess1)
NSString *all;
all = [combinedMess stringByAppendingString:mess1];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: title
message: all
delegate: self
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
This is not possible on iOS7 without creating your own version of an alert view. A quick google search came across this https://github.com/wimagguc/ios-custom-alertview which looks promising.
Per apple's documentation:
Subclassing Notes
The UIAlertView class is intended to be used as-is
and does not support subclassing. The view hierarchy for this class is
private and must not be modified.
https://developer.apple.com/library/ios/documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html
I have added a UITabBarController programatically (Search,Login) and I want to set second tabbaritem(Login) and its view to be selected when Login credentials are not correct.But I m unable to do it so ..Could not understand where I m going wrong ..?
Search *first = [[Search alloc] initWithNibName:#"Search" bundle:nil];
first.title=#"Search";
Login *second=[[Login alloc]initWithNibName:#"Login" bundle:nil];
second.title=#"Login";
NSArray *viewArray= [NSArray arrayWithObjects:first,second, nil];
tabBarController=[[UITabBarController alloc] init];
[tabBarController setViewControllers:viewArray animated:NO];
[tabBarController setSelectedIndex:2];
[self presentModalViewController:tabBarController animated:NO];
But here my SearchViewController is selected and displayed as default...Where i m going wrong..?
Error is in this line:
[tabBarController setSelectedIndex:2];
Counting starts not from 1 but from 0, so in your case you have to change it to:
[tabBarController setSelectedIndex:1];
I have multiple UITextFields and I want to attach them to an in app email. I can get one of them appear but not the rest. Here is what I am using.
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
[composer setMailComposeDelegate:self];
[composer setSubject:#"My Subject"];
[composer setMessageBody:AddNotesTextField.text isHTML:YES];
[self presentModalViewController:composer animated:YES];
[composer release];
Thank you
You got it right already for the body using:
[composer setMessageBody:AddNotesTextField.text isHTML:YES];
So just repeat the procedure with the other fields like so:
[composer setSubject:mySubjectTextField.text];
Or if you are asking how to use the input from multiple text fields into the body of the email, you simply have to use NSString's stringWithFormat:
[composer setMessageBody:[NSString stringWithFormat:#"you can place static %# text in between %# these variables",AddNotesTextField.text,someOtherField.text] isHTML:YES];
In string with format, you escape the default string to add a string using "%#" for every instance where you want to insert some other string. Then after the original string ends you enter the names of the input strings separated by commas. [NSString stringWithFormat:#"%#%#",x,y]
I've searched through all the questions and can't seem to find my answer.
I have the following IBAction. This is crashing every time you tap on the phone number. I have gone back to the DB and formatted the phone numbers to 5551235555 instead of (555)-123-5555.
- (IBAction)callPhone:(UIButton *)sender{
Bar *items = self.detailItem;
NSURL *pn = [NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", items.barPhone]];
[[UIApplication sharedApplication] openURL:pn];
}
- (void)setCallButton:(UIButton *)callButton{
Bar *items = self.detailItem;
[callButton setTitle:items.barPhone
forState:UIControlStateNormal];
}
Any code guidance would be appriciated.
Bar *items = self.detailItem; is not initiated, so that is why it is returning nil. Try the following:
Bar *items = [[Bar alloc] init];
items = self.detailItem;
Or what you should have done is make items an ivar for this particular class. Then you can initiate items once and use it throughout your class.
I want to try to make a weather app... but how do i get the weather info and use them in my app?
I heard about Google IPA but how to use it?
First pick the best weather API for your purpose:
https://stackoverflow.com/questions/507441/best-weather-apis
Most APIs, including Google, return their result in XML format.
Quickly written example code to get you started with the Google Weather API:
NSString * location = #"Amsterdam";
NSString * address = #"http://www.google.co.uk/ig/api?weather=";
NSString * request = [NSString stringWithFormat:#"%#%#",address,location];
NSURL * URL = [NSURL URLWithString:request];
NSError * error;
NSString* XML = [NSString stringWithContentsOfURL:URL encoding:NSASCIIStringEncoding error:&error];
// Extract current temperature the 'dirty' way
NSString * temp = [[[[XML componentsSeparatedByString:#"temp_c data=\""] objectAtIndex:1] componentsSeparatedByString:#"\""] objectAtIndex:0];
NSLog(#"It's currently %# degree in %#.", temp, location);
// Parse the XML with NSXMLDocument to extract the data properly
NSXMLDocument * doc = [[NSXMLDocument alloc] initWithXMLString:XML options:0 error:NULL];
Output:
It's currently 14 degree in Amsterdam.
I created sample iOS Weather app using- Swift,Protocaol oriented programming(POP), Codable, OpenWeatherMap Api, MVVM design pattern with Unit Test.
https://github.com/deepakiosdev/WeatherApp/tree/master
May be it will helpful for someone who is looking all these things.