Warning message when launch a map by UIApplication sharedApplication - iphone

I link the following openMap method to a button. The method does work but there is an error message at
NSLog(urlText);
The message shows format string is not a literal (potentially insecure).
Does anyone know how to eliminate this warning?
-(IBAction)openMap:(id)sender{
NSString* addressText = #"New York";
addressText = [addressText stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];
NSString* urlText = [NSString stringWithFormat:#"http://maps.google.com/maps?q=%#", addressText];
NSLog(urlText);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];
}

Change the NSLog to,
NSLog(#"%#", urlText);
Or, remove the NSLog completely ;-)

Related

encoding an url string if it contans the following string

I am using the code like
searchQuery = [searchQuery stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
NSString* urlString = [NSString stringWithFormat:#"http://google.com/#auto|en|%#", searchQuery];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
The code is run when I pressed a button app not open the browser, if I remove the last phrase "#auto|en|" it is working fine. How I can encode the string to give an url.
check the searchQuery it is not accepting your any parameters like this.. or give more description so other people can give proper response on it.

how to include rate this App button in a application

I have this code in a button click for ratting this app
-(IBAction)_clickbtnratethisApp:(id)sender
{
NSString *str = #"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa";
str = [NSString stringWithFormat:#"%#/wa/viewContentsUserReviews?", str];
str = [NSString stringWithFormat:#"%#type=Purple+Software&id=", str];
// Here is the app id from itunesconnect
str = [NSString stringWithFormat:#"%#289382458", str];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}
but nothing happens when I click the button,my need is I want to set a alert view to show like the ordinary alert like ratethisapp,nothanks,later.If I tap the ratethisapp I will redirected to the ring page of appstore.How to active this?Thanks in advance.
The itms-apps: URL syntax doesn't work on the simulator but works fine on the device, so that's probably the only thing wrong with your code and if you try it on a device it will work fine.
Unrelated tip: You can concatenate strings using the stringByAppendingString: and stringByAppendingFormat: methods, that will save some code versus the way you are building your string currently.

Unexpected error when trying to use NSLog()

I'm new to iOS develoment, and I'm trying to write an app that can scrape a website (HTML). Scraping google is just an example - I'm planning on scraping something a bit more complex...
My code is as follows:
#import "KppleViewController.h"
#import "TFHpple.h"
#implementation KppleViewController
#synthesize theButton;
- (IBAction)buttonPressed:(UIButton *)sender {
NSLog(#"button Pressed");
NSURL *url = [NSURL URLWithString: #"http://www.google.com"];
NSData *htmlData = [NSData dataWithContentsOfURL: url];
TFHpple *xpathParse = [[TFHpple alloc] initWithHTMLData:htmlData];
NSArray *elements = [xpathParse searchWithXPathQuery:#"//h3"];
TFHppleElement *element = [elements objectAtIndex:0];
NSString *h3Tag = [element content];
NSLog(#"x",h3Tag);
}
The problem is that I get an error when I attempt to write to console (via NSLog) to see if anything worked. The error that I get is "Data argument not used by format string"
I've searched all over the internet, to no avail. If I comment out the NSLog to see if I my previous code is correct, I get an error about the variable immediately above the NSlog (h3Tag) declared but not being used.
Any help would be greatly appreciated...
I'm also open to any other methods of scraping HTML...
You're being confused by this line:
NSLog(#"x",h3Tag);
All this line does is log the string x. The second argument is completely unused. What you want is something like this:
NSLog(#"%#", h3Tag);
or perhaps a bit more descriptive:
NSLog(#"h3Tag: %#", h3Tag);
The token %# inside of the format string indicates that this is where the next argument will be printed. You may want to read up on the String Format Specifiers or on Formatting String Objects in general.
use
NSLog(#"%#", h3Tag);
or
NSLog(h3Tag);
NSLog(#"x = %#",h3Tag);
Above line prints the value of h3Tag.
For more help about NSLog refer link: [http://www.cocoadev.com/index.pl?NSLog]

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.

uibutton onclick does not call/open web page

i have two buttons defined. one of them when clicked must open a compose mail screen and the other when clicked must call. i have this defined as below. but when the button is pressed, it does not open either
-(IBAction) phoneButtonPressed:(id) sender{
NSString *phoneNumber = [[NSString alloc] initWithString:#"4216483330"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
}
-(IBAction) mailButtonPressed:(id) sender{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"mailto:askalibrarian#mail.pitt.edu?subject=ULS Library"]];
}
For the phone#, the url should be prefixed with "tel:" like this:
NSString *phoneNumber = [[NSString alloc] initWithString:#"tel:4216483330"];
For the mail, the problem is you have a space in the url string (in "ULS Library") which needs to be escaped before giving it to NSURL:
NSString *urlString = #"mailto:askalibrarian#mail.pitt.edu?subject=ULS Library";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[urlString
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
See the Apple URL Scheme Reference.