In my code, I have this snippet to make a phone call with dialing prefix (basically, a "call me" button) :
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"telprompt://+0000000000"]];
if(SYSTEM_VERSION_LESS_THAN(#"7.0")) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:+0000000000"]];
}
I wonder if the iPhone will hide the dialing prefix when it's unnecessary (?).
Thanks,
For those interested, I found a easy way, using NSLocale currentLocale:
// Get the current locale.
NSLocale *currentLocale = [NSLocale currentLocale];
// Get country code, e.g. ES (Spain), FR (France), etc.
NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode];
if ([countryCode isEqualToString:#"FR"]){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"telprompt://0000000000"]];
}
else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"telprompt://+33000000000"]];
}
if(SYSTEM_VERSION_LESS_THAN(#"7.0")) {
if ([countryCode isEqualToString:#"FR"]){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel://0000000000"]];
}
else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:+ 33000000000"]];
}
}
Works deliciously.
Second answer to my own question :
according to this post, mobile Country code doesn't change when roaming : Does CTCarrier mobileNetworkCode change when roaming?
Best way is therefore :
{
CTTelephonyNetworkInfo *info = [CTTelephonyNetworkInfo new];
CTCarrier *carrier = info.subscriberCellularProvider;
NSLog(#"country code is: %#", carrier.mobileCountryCode);
// Get mobile network code
if ([carrier.mobileCountryCode isEqualToString:#"208"]){
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:#"telprompt://0000000000"]];
}
else {
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:#"telprompt://+33000000000"]];
}
if(SYSTEM_VERSION_LESS_THAN(#"7.0")) {
if ([carrier.mobileCountryCode isEqualToString:#"208"]){
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:#"tel://0000000000"]];
}
else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:+33000000000"]];
}
}
}
Works fine too.
Related
Before I asked this question I had try:
Use [[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=Privacy&path=LOCATION"]];It's work fine on iOS8 and iOS9,but there is nothing happen on iOS10.
Use [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];It's work fine on iOS8 and iOS9,too.However,on iOS10,when the app jump to system setting, the system setting exit immediately.
Use [[UIApplication sharedApplication]openURL:url options:#{}completionHandler:nil];It's crashed on iOS8 and iOS9,also,exit immediately on iOS10.
The question is can our app jump to system setting on iOS10? If yes.How?And for [[UIApplication sharedApplication]openURL:url options:#{}completionHandler:nil];what's the optionsmeans?We must code something for the options?
For some time now, apps have only been permitted to open their own settings pane in the settings app. There have been various settings URLs that have worked in the past, but recently Apple has been rejecting apps that use these URLS.
You can open your own application's settings:
if let url = URL(string:UIApplicationOpenSettingsURLString) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
Or in Objective-C
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if (url != nil) {
[[UIApplication sharedApplication] openURL:url options:[NSDictionary new] completionHandler:nil];
}
If you are targeting version of iOS earlier than 10 then you may prefer to use the older, deprecated, but still functional method:
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if (url != nil) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[[UIApplication sharedApplication] openURL:url];
#pragma clang diagnostic pop
}
Note:I use this method for a long time and everyting goes well,but today(2018-9-14),I had been rejected.
Here is my previous answer,do not use this method forever:
CGFloat systemVersion = [[UIDevice currentDevice].systemVersion floatValue];
if (systemVersion < 10) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"App-Prefs:root=Privacy&path=LOCATION"]];
}else{
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:#"App-Prefs:root=Privacy&path=LOCATION"]
options:[NSDictionary dictionary]
completionHandler:nil];
}
Now I use this way:
if (#available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:[NSDictionary dictionary] completionHandler:nil];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
Note :- this solution will not be useful for ios10 onwards
Dont forget to add URL schemes :-
Go to Project settings --> Info --> URL Types --> Add New URL Schemes-->URL Schemes = prefs
after that Use this url :-
let settingUrl = URL(string: "App-Prefs:root=Privacy&path=LOCATION")
And open using :-
if #available(iOS 10.0, *) {
UIApplication.shared.open(settingUrl) {
(isOpen:Bool) in
if !isOpen {
debugPrint("Error opening:\(settingUrl.absoluteString)")
// show error
}
}
}else{
if UIApplication.shared.canOpenURL(settingUrl) {
UIApplication.shared.open(settingUrl, completionHandler: { (success) in
print("Settings opened: \(success)") // Prints true
})
}
}
Enjoy :)..this worked for me.
Thanks to this guy. I figure out this URL Scheme Prefs:root=Privacy&path=LOCATION is only available in Today Widget, but no use in containing app.
In Today Widget, you can try this:
[self.extensionContext openURL:[NSURL URLWithString:#"Prefs:root=Privacy&path=LOCATION"] completionHandler:nil];
More about system URL Schemes, you can see here.
This all I got. Hope it will help you.
You can also open your app's setting center by opening"App-Prefs:root=your app bundle id". This will be easy for user to change setting for your app.
This works for me. iOS7 ~ iOS11
But if you are uing the iOS11, you can only jump to the app's setting page 😥
NSURL *url1 = [NSURL URLWithString:#"App-Prefs:root=Privacy&path=LOCATION"];
NSURL *url2 = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if (#available(iOS 11.0, *)) {
if ([[UIApplication sharedApplication] canOpenURL:url2]){
[[UIApplication sharedApplication] openURL:url2 options:#{} completionHandler:nil];
}
} else {
if ([[UIApplication sharedApplication] canOpenURL:url1]){
if (#available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:url1 options:#{} completionHandler:nil];
} else {
[[UIApplication sharedApplication] openURL:url1];
}
}
}
I had implemented a module for opening Skype app for various modules chat ,call, video call.It was working till iOS 8.
Below is link is followed for integration
https://msdn.microsoft.com/en-us/library/dn745885.aspx
But it stopped working in iOS 9 now.
The below code is just opening the App-store searching Skype even when Skype is installed
BOOL installed = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"skype:"]];
if(installed)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"skype:%#?chat",dataSource[indexPath.section]]]];
}
else
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"https://itunes.apple.com/in/app/skype-for-iphone/id304878510?mt=8"]];
}
Any Alternative for this?Please guide.Thanks
Below i am sharing the image which worked for me.
I added the key LSApplicationQueriesSchemes in Info.plist file for skype
BOOL installed = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"skype:"]];
if(installed)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"skype:%#?chat",dataSource[indexPath.section]]]];
}
else
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"https://itunes.apple.com/in/app/skype-for-iphone/id304878510?mt=8"]];
}
This question already has answers here:
What’s the correct URL for placing a call on an iPhone?
(5 answers)
Closed 9 years ago.
I'm trying to call a phone number from ios app using:
It's not working, although the method gets called:
-(IBAction)callPhone:(id)sender {
NSString *phoneCallNum = [NSString stringWithFormat:#"tel://%#",listingPhoneNumber ];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneCallNum]];
NSLog(#"phone btn touch %#", phoneCallNum);
}
NSLog output: phone btn touch tel://+39 0668806972
your code is correct. did you check in real device. this function will not work in simulator.
try this also,
NSString *phNo = #"+919876543210";
NSURL *phoneUrl = [NSURL URLWithString:[NSString stringWithFormat:#"telprompt:%#",phNo]];
if ([[UIApplication sharedApplication] canOpenURL:phoneUrl]) {
[[UIApplication sharedApplication] openURL:phoneUrl];
} else
{
calert = [[UIAlertView alloc]initWithTitle:#"Alert" message:#"Call facility is not available!!!" delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil, nil];
[calert show];
}
** Swift 3 version**
if let url = URL(string: "telprompt:\(phoneNumber)") {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(call, options: []) { result in
// do something with result
}
}
}
Telephony does not work on simulators/iPod/iPad, you will require to run the app on an iPhone with active sim card.
Also the URL scheme to invoke the telephony application is tel:<phone_number>. Refer Apple docs.
Ideally, you should check if the device is having the telephony module and then perform the openURL: call. Use this code to perform the check,
if([[UIApplication sharedApplication] canOpenURL:callUrl]) {
[[UIApplication sharedApplication] openURL:callUrl];
}
else {
//Show error message to user, etc.
}
Use following method to make call:
NSString *phoneNumber = [#"tel://" stringByAppendingString:number];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
You can try like below.
NSString *phoneNumber = [#"tel://" stringByAppendingString:Number];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
Hope it helps you.
NSString *phoneNumber = [#"tel://" stringByAppendingString:#"9414481799"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
This will only run on device.
I'm trying to integrate my app with waze.
Anyone know how can I call waze and send the coordinates?
I didn’t find any API or other information about it..
- (void) navigateToLatitude:(double)latitude
longitude:(double)longitude
{
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"waze://"]]) {
//Waze is installed. Launch Waze and start navigation
NSString *urlStr = [NSString stringWithFormat:#"waze://?ll=%f,%f&navigate=yes", latitude, longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]];
} else {
//Waze is not installed. Launch AppStore to install Waze app
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://itunes.apple.com/us/app/id323229106"]];
}
}
It's possible to open the Game Center app from your own app using:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"gamecenter:"]];
Is there a way to open it on the page for a specific game?
I've tried many different combinations. Judging by iBook's lack of such a feature, the lack of documentation and as I'm sure you've found—the lack of info on the internet—I'm going to say that someone'd probably have to either brute force the URL to figure it out (if it's set up to go to individual apps by URL at all). Here are some I've tried:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"gamecenter:id350536422"]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"gamecenter:us/app/cheese-moon/id350536422"]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"gamecenter:games/"]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"gamecenter:350536422"]];
UPDATE
I combed through the internals of the OS and found out the URL resolution patterns for Game Center:
You'll need to be savvy with regex to use all of them. Here are some I've typed out for you:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"gamecenter:/me/account"]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"gamecenter:/me/signout"]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"gamecenter:/friends/recommendations"]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"gamecenter:/games/recommendations"]];
The example URLs used in Cirrostratus's answer are missing a few bits.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"gamecenter://static.gc.apple.com/me/"]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"gamecenter://static.gc.apple.com/friends/"]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"gamecenter://static.gc.apple.com/games/"]];
These URLs seem to work for me on iOS 6 and 7. I'm assuming if you were signed into a sandbox Game Center account that you'd have to use sandbox.gc.apple.com instead. I tried to go to a specific game or friend page via /games/game/<id>/ and /friends/player/<id>/ but anything I try for ID doesn't seem to work. For the friends URL I go to a blank friend page.
Even if someone did figure it out, because it's undocumented Apple could change at any time in the future so I wouldn't hardcode a URL like this into an app.
Only use this routine .
- (void)showGameCenter
{
GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
if (gameCenterController != nil)
{
gameCenterController.gameCenterDelegate = self;
gameCenterController.viewState = GKGameCenterViewControllerStateDefault;
[self presentViewController: gameCenterController animated: YES completion:nil];
}
}