How to send action from my app to other app? - ios

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.

Related

Is there a way to hide "Back to Safari" from status bar in iOS9?

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

Prevent Phone Screen Popping Up

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.

How to open WhatsApp programmatically and then get back to my app?

In my app I need to send links via WhatsApp. So this is how I do that:
NSString* link = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,
(CFStringRef)resource.shareURL.absoluteString,
NULL,
CFSTR("!*'();:#&=+$,/?%#[]"),
kCFStringEncodingUTF8));
NSString * urlWhats = [NSString stringWithFormat:#"whatsapp://send?text=%#", link];
NSURL * whatsappURL = [NSURL URLWithString:urlWhats];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
} else {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Unknown error"
message:#"Can't open Whatsapp"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
But the problem is that it doesn't return automatically to my app after the message is sent. User needs to get back to the app manually. So how do I make it return to my app? Is it even possible?
It's not possible. The only theoretic way for this to work would be to send URI for your app to be opened by whatsapp in their completion handler. However, whatsapp scheme doesn't support such things so there is no way to force it to open your app after it has sent the message.

Hide Outgoing Call Screen in iOS

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.

Check if Google Maps App is installed in iOS 6

I am trying to figure out how to handle the result of this code to see if Google Maps is installed in the app.
[[UIApplication sharedApplication] canOpenURL:
[NSURL URLWithString:#"comgooglemaps://"]];
I am creating a UIAlertView with the option in there and if it is or isn't I wish to give the user different options.
How do I take the result of the code above and turn it into a BOOLEAN?
Thanks in advance.
The result is already of canOpenURL: a boolean:
BOOL canHandle = [[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:#"comgooglemaps:"]];
if (canHandle) {
// Google maps installed
} else {
// Use Apple maps?
}
Above for iOS 9.0
Step 1. Add comgooglemaps in LSApplicationQueriesSchemes in your apps info.plist
Step 2.
BOOL isGoogleMap = [[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:#"comgooglemaps://"]];
UIAlertView *alert;
if(isGoogleMap)
{
alert = [[UIAlertView alloc]
initWithTitle:#"Get Directions"
message:#"Show Map"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"View in Apple Maps", #"View in Google Maps", nil];
}
else
{
alert = [[UIAlertView alloc]
initWithTitle:#"Get Directions"
message:#"Show Map"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"View in Apple Maps", nil];
}
alert.tag = 1010;
[alert show];

Resources