Sygic URL scheme - App does not open - ios

I am trying to integrate the most popular navigation apps into my app, and all of those I chose work, except for Sygic.
Following this guide, I wrote the code:
NSString *URL = [NSString stringWithFormat:#"com.sygic.aura://coordinate|%f|%f|drive",
self.coordinate.longitude,
self.coordinate.latitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:URL]];
But when the code is run, Sygic doesn't open, nothing happens.
Checking [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"com.sygic.aura://"]] returns YES when the app is installed and NO when it's not (as it should).
I tested using "Sygic Brasil" and "Sygic (All Regions)", version 13, but neither will open.
I also tried percent-escaping the URL string, and that didn't work either.

you try following code,
NSString *URL = [NSString stringWithFormat:#"com.sygic.aura://coordinate|%f|%f|drive",
self.coordinate.longitude,
self.coordinate.latitude];
NSURL *newURL = [NSURL URLWithString:[URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ];
if(newURL)
{
[[UIApplication sharedApplication] openURL:newURL];
}
else
{
NSLog(#"Something wrong with lat or long or both");
}

Related

opening a received url with safari

I am receiving a url from a server request, I made a button , when pressed, safari must open and go to the link,
My code below:
- (IBAction)openFeedbackWebViewPresser:(id)sender {
NSString *feedbackUrl = self.getConfig.feedbackURL;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: feedbackUrl]];
}
If I print the feedback url , its as below:
https://xxx.xxxxx.com/CRM/feedback#/1715171559ae979371687#/10306
I tried to use another way:
NSURL *url = [NSURL URLWithString:feedbackUrl];
[[UIApplication sharedApplication] openURL: url];
the url is returning nil, knowing that the feedbackUrl contains a url.
Any idea whats wrong?
Thanks
Might be your string url is containing any spaces or any other special characters that must be encoded. like below
NSString *feedbackUrl = [self.getConfig.feedbackURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: feedbackUrl]];
hope it helps.!!!
This might be happening because of the special characters that must be encoded. The following encoding works for me-
NSString *feedbackUrl = [self.getConfig.feedbackURL stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: feedbackUrl]];
This is the code to open the link in browser, Hope this help
- (IBAction)emailButton:(id)sender {
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:self.emailLabel.text]];
}

Make a phone call from UIWebView without prompt

SCENARIO
I have an app that is a UIWebView, I make some url overriding for requirements.
PROBLEM
To make a call opening url with tel: works weird in iOS7 and iOS8, it makes the phone call direct in the background, but it also ask for the confirmation, so user experience is horrible:
[[UIApplication sharedApplication] openURL:request.URL];
SOLUTION
To solve this issue, I used telprompt. It works nice in all iOS versions:
NSURL *url = [NSURL URLWithString:#"telprompt://637****"];
return [[UIApplication sharedApplication] openURL:url];
But shows this confirmation dialog:
QUESTION
Now, I have a new requirement, to make the phone call without confirmation or prompt. So... There is some way to make a phone call in iOS omitting the confirmation prompt?
I want something like
NSURL *url = [NSURL URLWithString:#"telnoprompt://637******"];
return [[UIApplication sharedApplication] openURL:url];
NSMutableCharacterSet *characterSet =[NSMutableCharacterSet characterSetWithCharactersInString:#" "];
NSArray *arrayOfComponents = [phone_number componentsSeparatedByCharactersInSet:characterSet];
phone_number = [arrayOfComponents componentsJoinedByString:#""];
NSString *phoneURLString = [NSString stringWithFormat:#"tel:%#", phone_number];
NSString *escapedUrlString = [phoneURLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *phoneURL = [NSURL URLWithString:escapedUrlString];

Open Settings warning issue in Xcode 6.3: Comparison of address of 'UIApplicationOpenSettingsURLString' not equal to a null pointer is always true

I'm not inventing the wheel. In iOS8, to open Settings from inside the app I'm using this code:
BOOL canOpenSettings = (&UIApplicationOpenSettingsURLString != NULL);
if (canOpenSettings)
{
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];
}
The code is in a lot of answers and questions in stackoverflow.
The problem came out with Xcode 6.3, I've got a warning saying:
Comparison of address of 'UIApplicationOpenSettingsURLString' not equal to a null pointer is always true
What is interesting is that Apple is using it in their example code:
https://developer.apple.com/library/ios/samplecode/AppPrefs/Listings/RootViewController_m.html
Some idea about how to avoid the warning and still checking if I can open Settings?
SOLVED:
The problem is related with the Deployment Target in the App.
If the Target is 8.0 or above, the comparison will be always true because you are always over 8.0. So we do not need the if verification:
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];
Another option can be:
NSURL *settings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:settings])
{
[[UIApplication sharedApplication] openURL:settings];
}
I believe this is because &UIApplicationOpenSettingsURLString is never nil in this version so you can just directly use the following to launch settings:
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];

Hyperlink from Plist in Xcode

I have a button in my app when clicked is supposed to take you to the website of the business which is stored in a plist. I can get the button to work with this code:
-(IBAction)search:(id)sender{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.google.com"]];
}
Now how can I manipulate this code to call the website from a plist already established.
Get the link string from the p-list.
NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Info" ofType:#"plist"]];
NSString * urlString = dictionary[#"TheKeyPath"]; // theKeyPath referring to the key that you assigned to the url string in the p-list
Then very simple...
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
I wrote it like this but the button never appears to do anything, I wrote an NSLog and it does click the button but does not send to safari.
-(IBAction)search:(id)sender{
NSString *searchsite = [resultDic objectForKey:#"Search"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:searchsite]];
}
What is confusing is I have a call function wrote like this and it works just fine.
-(IBAction)callPhone:(id)sender {
NSString* yourActualNumber = [NSString stringWithFormat:#"tel:%#",resultDic[#"Phone"]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:yourActualNumber]];
}

launch youtube channel in youtube app

For launching video on youtube app, I am using below code.
NSURL *instagramURL = [NSURL URLWithString:#"youtube://foo"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
NSLog(#"opening youtube app...");
NSString *stringURL = #"http://www.youtube.com/watch?v=H9VdapQyWfg";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
} else {
// open in UIWebView in WebViewViewController
WebViewViewController *secondView = [self.storyboard instantiateViewControllerWithIdentifier:#"webinterface"];
secondView.headerLabel = #"YouTube";
secondView.webPath = #"http://www.youtube.com/watch?v=H9VdapQyWfg";
[self.navigationController pushViewController:secondView animated:YES];
}
Now client changed the mind and asking to put channel in iPhone app.
For testing, I used link http://www.youtube.com/user/richarddawkinsdotnet
BUT when I use this link, instead of youtube app, it always opens in SAFARI. :(
Any idea/ suggestion on how can I open channel in YouTube app with link provided?
You're code's going wrong because, although you're checking if you can open the youTube URL more or less correctly, you're then just opening a web address, which will always open in Safari.
This is the code I've just used, which is working for me. You might want to modify the else statement if you want to fallback to using a webviewcontroller as this will open Safari if the youtube app isn't installed.
NSString *channelName = #"TheNameOfTheChannel";
NSURL *linkToAppURL = [NSURL URLWithString:[NSString stringWithFormat:#"youtube://user/%#",channelName]];
NSURL *linkToWebURL = [NSURL URLWithString:[NSString stringWithFormat:#"http://www.youtube.com/user/%#",channelName]];
if ([[UIApplication sharedApplication] canOpenURL:linkToAppURL]) {
// Can open the youtube app URL so launch the youTube app with this URL
[[UIApplication sharedApplication] openURL:linkToAppURL];
}
else{
// Can't open the youtube app URL so launch Safari instead
[[UIApplication sharedApplication] openURL:linkToWebURL];
}
Same answer, but shorter:
if (![[UIApplication sharedApplication] openURL: [NSURL URLWithString: #"youtube://user/%channelName%"]]) {
NSURL *webURL = [NSURL URLWithString:#"http://www.youtube.com/user/%channelName%"];
[[UIApplication sharedApplication] openURL: webURL];
}
and twitter:
if (![[UIApplication sharedApplication] openURL: [NSURL URLWithString: #"twitter://user?screen_name=%channelName%"]]) {
NSURL *webURL = [NSURL URLWithString:#"http://twitter.com/%channelName%"];
[[UIApplication sharedApplication] openURL: webURL];
}
And here is a more exhaustive list of apps:
http://wiki.akosma.com/IPhone_URL_Schemes
youtube://user/<channel-id> stopped working in iOS 9 so i research and found this working well now in iOS 9
youtube://www.youtube.com/channel/<channel-id>

Resources