iOS: Instagram hook with special characters - objective-c

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"];

Related

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");
}

Remove part of the url

I am working with Sencha Touch and PhoneGap. The code is for iOS and it's waiting for url with suffix #phonegap-external ..
- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
if ( ([url fragment] != NULL) && ([[url fragment] rangeOfString:#"phonegap=external"].location != NSNotFound))
{
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
return NO;
}
}
return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
}
So because I haven't written any line of code in Obj-C, I need your help. Can someone edit code, so that it would open url without suffix.
EDIT:
If user opens url in app, it would open it inside webview but on occasion I would prefer that url is opened in Safari. So this code checks if url has suffix like this - http://google.com#phonegap-external and than it opens it in Safari. Only thing what bugs me, is url is not changed into http://google.com and it opens given url http://google.com/#phonegap-external. Could someone please fix this.
If you're sure that the part of the URL that indicates whether it's to be opened inline or externally (i. e. the #phonegap-external string) is always the last one in the URL, then you can try removing this suffix by writing something like as follows:
NSString *orig = [url absoluteString];
size_t frLen = [#"phonegap-external" length];
NSString *stripped = [orig substringToIndex:orig.length - frLen];
NSURL *newURL = [NSURL URLWithString:stripped];
[[UIApplication sharedApplication] openURL:newURL];

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.

Make a phone call when click on a phone number String

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];