Make a phone call when click on a phone number String - objective-c

I have a phone number like this: 025639879. I got it from the database as a String.
Now i want to make a Phone call exactly when the user click on that number, i have tried to do like this:
NSString *phoneNumber=[#"tel://"stringByAppendingString:myAppGlobalVariables.telephoneTheme];
NSString *html = [NSString stringWithFormat:#"<html><body>Téléphone:%#</body
</html>",phoneNumber];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
[webView loadHTMLString:html baseURL:nil];
What i got in my app is this:
Téléphone:tel://025639879
Am i missing something? thanx in advance.

You can do it in two ways:
skip the tel:// and make your webview recognize phone numbers as links (there will be false positives so be careful with this).
make a number link:
NSString *html = [NSString stringWithFormat:#"<html><body><p>Téléphone:%#</p></body></html>", myAppGlobalVariables.telephoneTheme, myAppGlobalVariables.telephoneTheme];
[webView loadHTMLString:html baseURL:nil];

Related

iOS: Instagram hook with special characters

I am trying to open Instagram from my app. The tag should contain some norwegian special characters, but the Instagram app is not lauching when I try to execute the code below. I tried with the code example below, and with UTF8 encoding, but without success. As soon as I add a tag without these characters, Instagram launches. Any tips on how to handle this characters?
NSString* hashtag = [NSString stringWithFormat:#"%#", #"instagram://tag?name=øæå"];
NSURL *instagramURL = [NSURL URLWithString:hash];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
[[UIApplication sharedApplication] openURL:instagramURL];
}
Try with the percent escapes like this:
NSString* hashtag = [NSString stringWithFormat:#"%#", #"instagram://tag?name=%C3%B8%C3%A6%C3%A5"];

how to open phone app in iphone without using "tel://123" url [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Can I open phone app using url scheme in iPhone
Within app, I need to launch the phone app. I do not want to dial a call right away like the code below:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#\"tel://911\"]];
....which would just dial 911. I am wondering if I can just launch the phone app. I tried this code:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#\"tel://\"]];
But it doesnot work
Please help me in solving this issue
You can't do that. However if you replace tel: with telprompt: it will prompt the user to confirm the call.
Edit: Also, #"a string" is the syntax literal for NSString. You shouldn't escape the quotes.
Try this code :-
NSString *prefix = (#"tel://123");
UIApplication *app = [UIApplication sharedApplication];
NSString *dialThis = [NSString stringWithFormat:#"%#", prefix];
NSURL *url = [NSURL URLWithString:dialThis];
[app openURL:url];
NOTE : Telephone number should be valid format only
Hope it helps you

Entering textfield values into an URL

So I'm in the progress of developing an app but I'm kinda stuck at the moment. I have 2 textfields right now that the user will have to enter:
Ordernr:xxxxxxxx
Referencenr:xxxxxxx
these 2 values have to be added to this link:
http://www.artis-web.de/cgi-bin/WebObjects/Artis.woa/wa/detailedTrack?referencenr=xxxxxxxx&ordernr=xxxxxxxxxx
now I want safari to open this link. The ideal situation would be the user entering the 2 textfields values and then pressing a button called "open in safari"
What would be the best way to implement this?
Just add the following code to your button action:
NSString *urlString = [NSString stringWithFormat:#"http://www.artis-web.de/cgi-bin/WebObjects/Artis.woa/wa/detailedTrack?referencenr=%#&ordernr=%#", referenceNrTextField.text, orderNrTextField.text];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: urlString]];
To create the URL you can use...
NSURL *url = [NSURL urlWithString:[NSString stringWithFormat:#"http://www.artis-web.de/cgi-bin/WebObjects/Artis.woa/wa/detailedTrack?referencenr=%#&ordernr=%#", referenceTextField.text, ordernoTextField.text]];
To open in safari...
[[UIApplication sharedApplication] openURL:url];
Check whether the both fields have data and then hit the url with the given data.This condition would be sufficient.
if (Ordernr.text.length!=0 && Referencenr.text.length!=0)
{
NSLog(#"Hit the Url with the entered data");
}
else
{
NSLog (#"Show Error Alert Message");
}

Xcode openURL doesn't read link

I have an animal list and special button. When I press the button, I would like to go to Wikipedia and read about this animal more. So I wrote this code:
-(IBAction)goWiki:(id)sender
{
NSString *wikiUrl = "http://ru.wikipedia.org/wiki/";
NSString *url = [NSString stringWithFormat:#"%#%#",wikiUrl,animalTitle];
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:url]];
NSLog(#"%#",url);
}
NSLog shows that url was written correctly, however, nothing happened. I am 99,9% sure its because of animalTitle. My native language is russian and animalTitle is also an animal name in russian.
So if link is like http://ru.wikipedia.org/wiki/Frog its fine and it works but if its like
http://ru.wikipedia.org/wiki/Лягушка nothing happens.
Any ideas, how can I move to a russian article?
Thanks!
use stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding as follows -
-(IBAction)goWiki:(id)sender
{
NSString *wikiUrl = #"http://ru.wikipedia.org/wiki/";
NSString *url = [NSString stringWithFormat:#"%#%#",wikiUrl,animalTitle];
url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:url]];
NSLog(#"%#",url);
}
Try passing the string animalTitle through CFURLCreateStringByAddingPercentEscapes first.

Loading HTML into a Cocoa app with WebView and change text

Right, so far I've got this for loading up a HTML file from within my app:
NSString *path1 = [[NSBundle mainBundle] pathForResource:#"file" ofType:#"html"];
NSString *html = [NSString stringWithContentsOfFile:path1 encoding:NSUTF8StringEncoding error:nil];
[[webView mainFrame] loadHTMLString:html baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]bundlePath]]];
Which works loading the file up into the app's WebView. But I want to change some values in the HTML (or PHP if it works by using $_REQUEST/$_GET), for example, I have a table with some text in it and I want to change this text from an NSString etc.
How would I go about this?
You can execute JavaScript on UIWebView, if you need to do that dynamically.
Or, if you want to refresh the whole page, you can modify string loaded from file according to your preferences.