How to hide this < Back to Safari from status bar programmatically?
I'm getting it in my app – as I'm going out from my app if a user wants to login with their Facebook account.
Here's the scenario for which I don't like (want) "Back to Safari" in my app.
At first launch of the app (and user not logged in).
User choose Login with Facebook option.
Facebook iOS SDK comes into the picture, it takes me to the Safari.
I logged in and back to the app
But, there's "Back to Safari"... It shouldn't be here anymore.
No, there is no API that lets you do this.
You can achieve this by forwarding to a website with a forward back to your app. The following steps allows you to hide the 'Back to Safari' in the status bar, MyApp is the example app name:
Add your application URL Scheme to the Info.plist
<key>LSApplicationQueriesSchemes</key>
<array>
<string>myapp</string>
</array>
Setup a custom URL forward on a website (e.g. http://example.com/myapp)
_redirect_rule_from /myapp
_redirect_rule_to myapp://
In your authorization method closure hit the forward you created in step 2
- (void)willLoginWithFacebook
{
__weak __typeof(self) weakSelf = self;
[self.view setUserInteractionEnabled:NO];
[self.sessionManager authenticateViaFacebookWithCompletion:^(NSString *token, NSSet *grantedPermissions,
NSError *error) {
if (error) {
if (error.code != myappErrorCodeCancelled) {
[weakSelf.rootViewController presentError:error];
}
}
else {
[weakSelf authorizeWithFacebookToken:token];
NSString *customURL = #"myapp://";
if ([[UIApplication sharedApplication]
canOpenURL:[NSURL URLWithString:customURL]])
{
NSString *stringURL = #"http://example.com/myapp";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"URL error"
message:[NSString stringWithFormat:
#"No custom URL defined for %#", customURL]
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
};
}];
}
I want to send action from my iOS app to other app
UIApplication *ourApplication = [UIApplication sharedApplication];
NSString *URLEncodedText = #"...";
NSString *ourPath = [#"...://" stringByAppendingString:URLEncodedText];
NSURL *ourURL = [NSURL URLWithString:ourPath];
if ([ourApplication canOpenURL:ourURL]) {
[ourApplication openURL:ourURL];
}
else {
//Display error
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"..." message:#"..." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
Now, open second app from my app, but I want send action to second app.
Apple added Actions to iOS8 to manage this kind of problems. You can check the docs here.
This way you can offer "services" as Actions to another apps or, if it's your case, consume that actions offered by third party apps.
I have an app I'm working on that when a button is pressed will call a number on the iPhone. That said, I want to prevent the phone screen from popping up and instead keep the app open as is. Here's my code so far. I have no idea if this is even possible. Any help would be great.
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];
}
All calls made through traditional phone numbers can only use the iPhone's phone app.
As has been suggested, if you create your own VOIP service or use an existing one, you'll be able to process this call in-app as a data call.
I am facing a problem from last 2 days. According to my requirement when I call to another number through coding, I have to call directly without showing Call Screen. When I pressed the call button then call will be transfer in Background. The Call screen will not be shown on screen.
My code for call on Button:
- (IBAction)callBtn_Action:(id)sender
{
NSString *phNo = #"02233814006";
NSURL *phoneUrl = [NSURL URLWithString:[NSString stringWithFormat:#"tel:%#",phNo]];
if ([[UIApplication sharedApplication] canOpenURL:phoneUrl])
{
[[UIApplication sharedApplication] openURL:phoneUrl];
}
else
{
UIAlertView *calert = [[UIAlertView alloc]initWithTitle:#"Alert" message:#"Call facility is not available!!!" delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil, nil];
[calert show];
}
}
Is it possible? Please anybody help me..
iOS does not support directly calling a number. The best you can do is show the screen with a populated number to dial. There is no work around for this.
How can I dial a phone number that includes a number and access code programmatically in iOS?
For example:
number: 900-3440-567
Access Code: 65445
UIDevice *device = [UIDevice currentDevice];
if ([[device model] isEqualToString:#"iPhone"] ) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"tel:130-032-2837"]]];
} else {
UIAlertView *notPermitted=[[UIAlertView alloc] initWithTitle:#"Alert" message:#"Your device doesn't support this feature." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[notPermitted show];
[notPermitted release];
}
follow the tutorial
http://www.makebetterthings.com/blogs/iphone/open-phone-sms-email-map-and-browser-apps-in-iphone-sdk/
to call a number use -
NSURL *url = [NSURL URLWithString:#"tel://012-4325-234"];
[[UIApplication sharedApplication] openURL:url];
to open your app after call finished use -
(Note: telprompt is undocumented)
NSURL *url = [NSURL URLWithString:#"telprompt://012-4325-234"];
[[UIApplication sharedApplication] openURL:url];
You can programmatically dial phone numbers using UIApplication's openURL: method (see example below). I'm unsure if access codes are supported, but this is at least a starting point.
NSURL *URL = [NSURL URLWithString:#"tel://900-3440-567"];
[[UIApplication sharedApplication] openURL:URL];
Edit: See the Apple URL Scheme Reference and the UIApplication Class Reference for more information.
I don't know if you actually found a solution for passing the access code, but for me this code worked:
NSString *dialstring = [[NSString alloc] initWithFormat:#"tel:your_phonenumber,your_accessnumber"];
That will result in a dial string with the following values:
tel:9003440567,65445
The remaining parts are managed by the phone app of iOS with the following command:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:dialstring]];
The , in the string causes a pause in your telephonesystem (the one where you want to access a conference room) right after the first number is dialed and a connection is established. So the telephonesystem has time to ask you for the access code (I think it should ask you, that's the way our system works). And after that your access code should be passed.
BE AWARE: Your access code will be passed in in a non-secret way. For example: Your shown access code will be displayed in the iPhone phone app display this way: 9003440567, 65445
Using this user can redirect on Call and after the call he/she will automatically redirected to the app. It's working for me and sure about it.
if ([[device model] isEqualToString:#"iPhone"] ) {
NSString *phoneNumber = [#"telprompt://" stringByAppendingString:cellNameStr];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
} else {
UIAlertView *warning =[[UIAlertView alloc] initWithTitle:#"Alert" message:#"Your device doesn't support this feature." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[warning show];
}
Here is a self-contained solution in Swift:
private func callNumber(phoneNumber:String) {
if let phoneCallURL:NSURL = NSURL(string: "tel://\(phoneNumber)") {
let application:UIApplication = UIApplication.sharedApplication()
if (application.canOpenURL(phoneCallURL)) {
application.openURL(phoneCallURL);
}
}
}
Now you should be able to use callNumber("7178881234") to make a call; hope this helps!
You can use Phone urls to invoke the Phone application to dial a number for you. See this reference.
The downside is that once the call is finished, user will endup in the Phone application. But I am afraid there is no solution to that problem. iOS doesn't allow any application to directly initiate a call because of security and privacy reasons.
You can use comma for introducing pause(s) while dialing a number.
It's not possible to dial programmatically a phone number that includes number and access code.
The Apple Developer Library gives the following info:
"...the Phone application supports most, but not all, of the special characters in the tel scheme. Specifically, if a URL contains the * or # characters, the Phone application does not attempt to dial the corresponding phone number."
See: Apple URL Scheme Reference
There are a number of ways to dial a phone number and the way described that uses:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:555-555-5555"]
Is a valid way to do this however it has a number of issues. First it doesn't properly prompt the user and secondly it doesn't bring the user back to the application when the phone call is completed. To properly place a phone call you should both prompt before the call so you don't surprise the user and you should bring the user back to the application once the call is done.
Both of these can be accomplished without using a private API as is suggested by some of the answers here. The recommended approach uses the telprompt api but it doesn't use the private instantiation of the call and instead creates a web view allowing for future compatibility.
+ (void)callWithString:(NSString *)phoneString
{
[self callWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"tel:%#",phoneString]]];
}
+ (void)callWithURL:(NSURL *)url
{
static UIWebView *webView = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
webView = [UIWebView new];
});
[webView loadRequest:[NSURLRequest requestWithURL:url]];
}
A sample project and additional information is provided here:
http://www.raizlabs.com/dev/2014/04/getting-the-best-behavior-from-phone-call-requests-using-tel-in-an-ios-app/
Swift 5.0:
In case someone needed an updated swift code:
private func callNumber(phoneNumber:String) {
if let phoneCallURL:NSURL = NSURL(string: "tel://\(phoneNumber)") {
let application:UIApplication = UIApplication.shared
if (application.canOpenURL(phoneCallURL as URL)) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(phoneCallURL as URL)
} else {
UIApplication.shared.openURL(phoneCallURL as URL)
}
}
}
}