Cant launch Map from app on iOS 6 [duplicate] - iphone

This question already has answers here:
Programmatically open Maps app in iOS 6
(12 answers)
Closed 10 years ago.
I am trying to launch a map from within my app, and I am using the following:
- (void) showMap:(id) button {
UIApplication *application = [UIApplication sharedApplication];
NSString *address = [((PhoneButton *) button).cell.client fullAddress];
NSString *addressUrl = [NSString stringWithFormat: #"http://maps.apple.com/?q=%#", address];
NSLog(#"Maps String: %#", addressUrl);
NSURL *map_url = [NSURL URLWithString:addressUrl];
[application openURL:map_url];
};
Well, it is not working. I tried to find the issue but looks like I am doing it right. So, what am I missing?
PS: My address format is like "800, Madison Ave, New York, NY"

Try this.
Your address format is like
"800, Madison Ave, New York, NY"
which contain space between words. Remove space with "+" sign. your final URL should be like below URL.
with this you can launch Map from app on iOS 6.
http://maps.apple.com/?q=800,+Madison+Ave,+New+York,+NY

URLs can't have spaces. Spaces and other special characters need to be escaped properly. You want:
NSString *escapedAddress = [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *addressUrl = [NSString stringWithFormat: #"http://maps.apple.com/?q=%#", escapedAddress];

Related

Passing NSString in NSURL causes app crash [duplicate]

This question already has answers here:
NSURL returns Nil Value
(2 answers)
Closed 8 years ago.
I am passing NSString to NSURL and app crashes. I think this is due to 's used in NSString
NSLog of the NSString is
http://www.test.com/?AssessmentID=040714114412 &QuestionID=113&ResponseText=yes&AssessmentName=Housekeeping&AssessmentDate=11:44:21&AssessmentQuestion=Use the guest’s or employee’s name.&ResponseComment=No comment&DepartmentID=9&SectionName=Service Standards
here is the exception
[NSURL initWithString:relativeToURL:]: nil string parameter'
I think it is crashing due to guest's 's
The problem is your URL is not properly encoded. Take this & modify your code accordingly.
NSString *relativeURL = #"http://www.something with Space and parameters";
NSURL *url = [NSURL URLWithString:[relativeURL stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];
This is the right approach rather than replacing white spaces with %20
Hope that helps.
Well i tried out the following piece of code and it is working for me... can you do this as per the following code!
NSString *relativeToURL = #"http://www.test.com/?AssessmentID=040714114412 &QuestionID=113&ResponseText=yes&AssessmentName=Housekeeping&AssessmentDate=11:44:21&AssessmentQuestion=Use the guest’s or employee’s name.&ResponseComment=No comment&DepartmentID=9&SectionName=Service Standards";
NSURL *url = [[NSURL alloc] initWithString:relativeToURL];
[self.webView loadRequest:[NSURLRequest requestWithURL:url]];

calling phone number within the app issue

I have the following code:
phoneNumber = (NSString*)CFBridgingRelease(ABMultiValueCopyValueAtIndex(phones, i));
NSString *phoneNumberURLString = [[NSString alloc] initWithFormat:#"tel://%#", phoneNumber];
NSURL *phoneURL = [[NSURL alloc] initWithString:phoneNumberURLString];
[[UIApplication sharedApplication] openURL:phoneURL];
However, the issue with this is that, sometimes a certain phone number doesn't get called: for example if phoneNumber is (520) 123-1232, then this doesn't call the phone. Any idea on how to standarize the phone number format such that this method works for all cases?
It is the spaces in the number. A space is not a valid URL character. It must be encoded propery as %20.

How to load address in webview in iPhone? [duplicate]

This question already has an answer here:
Forward Geocode Example using CLGeocoder
(1 answer)
Closed 4 months ago.
Currently i am working in iPhone application, Using UIWebview to load address like "America", then run the application, the map not shown on the screen. I want to shown the location from User enter search bar field, How to fix this iuissue? please help me
Thanks in Advance
I tried this:
webView=[[UIWebView alloc]initWithFrame:CGRectMake(0, 40, 320,376)];
webView.delegate=self;
webView.scalesPageToFit=YES;
NSString *mapurl = #"http://maps.google.com/maps?q=";
NSString *urlString1 = [mapurl stringByAppendingFormat:#"America"];
NSString *OmitSpace = [urlString1 stringByReplacingOccurrencesOfString:#" " withString:#"%20"];
NSURL *url=[NSURL URLWithString:OmitSpace];
NSURLRequest *requestObj=[NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
Screen shot:
NSString *OmitSpace = [urlString1 stringByReplacingOccurrencesOfString:#" " withString:#"%20"];
This will omit the whitespace only. It will not convert other escape characters. So replace above line with this.
NSString *OmitSpace = [urlString1 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]

how to make a call in iphone? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to make a call programmatically?
In my App, I have one view in which complete address along with phone number of a company gets displayed. What i want is, when a user touches that phone number, it should make a call..
So, how to do it, when user touches that phone number.
Any answer will be appriciated. Thank you guys.
If you put the text in a UITextView there is a setting for it to automatically detect phone numbers. The OS will then highlight the phone number, and if the user taps on it, it will prompt them if they wish to call that number
-(IBAction)callPhone:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:1234567890"]];
}
Then connect TouchUpInside to this and you are good to go. Hope that helps!
-(void)callPhone:(id)sender{
NSURL *url = [NSURL URLWithString: #"tel://848444488"];
NSLog(#"Call %#", url);
[[UIApplication sharedApplication] openURL:url];
}
if the phone is in the form 848 44 44 88 use this code to eliminate spaces:
NSString *phoneWithoutSpaces = [[NSString stringWithFormat:#"tel://%#", #"848 44 44 88"] stringByReplacingOccurrencesOfString:#" " withString:#""];
NSURL *url = [NSURL URLWithString:phoneWithoutSpaces];
Do this
NSString *phoneNumber = [NSString StringWithFormat:#"tel:%#", textField.text];
[[UIApplication SharedApplication] openURL:[NSURL URLWithString:phoneNumber]];

How to call a phone from a number entered in a UITextField?

I'd like to make a button call a phone number entered by the user inside the text field. I have a code but it doesn't work.
NSString * phoneNumber = [NSString stringWithFormat:#"%#%#", #"tel://", phoneNumber.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
Anyone has a similar approach to this? Thanks.
I think it's tel: instead of tel://. See this Apple document. Try giving this a shot:
NSString *pn = [#"tel:" stringByAppendingString:phoneNumber.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:pn]];
See my answer to another question for some sample code to handle cases with invalid input.
Basically you do this:
NSString *cleanedString = [[phoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:#"0123456789-+()"] invertedSet]] componentsJoinedByString:#""];
NSString *escapedPhoneNumber = [cleanedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:#"tel://%#", escapedPhoneNumber]];
Update: I noticed that the string you created shares the some name ("phoneNumber") as the text field from which you try to get the text. You may want to rename either of those two.