open Whats app from iOS application and handle cancel click in iOS? - ios

In my application having sharing text on whatsapp... and when cancel from whatsapp its back to original ios app ..
i don't know how to handle cancel click of whatsapp in ios ..
please resolved my problem ..
i used below code for sharing text...
NSString * msg = #"YOUR MSG";
NSString * urlWhats = [NSString stringWithFormat:#"whatsapp://send?text=%#",msg];
NSURL * whatsappURL = [NSURL URLWithString:[urlWhats stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
} else {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"WhatsApp not installed." message:#"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}

Related

How to share on whatsapp without opening UIActivityViewController?

I want to open whatsapp directly to share video .
Now its open UIActivityViewController and then I have to select whatsapp
and I dont want this.
Hope it work
NSString *str = #"http://r.yoz.io/PJ.c.d?";//video url
str = [NSString stringWithFormat:#"%#id=%#",str];
str = [str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
CFStringRef originalURLString = (__bridge CFStringRef)[NSString stringWithFormat:#"%#",str];
CFStringRef preprocessedURLString = CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, originalURLString, CFSTR(""), kCFStringEncodingUTF8);
NSString *urlString = (__bridge NSString*)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, preprocessedURLString, NULL, CFSTR("!*'();:#&=+$,/?%#[]"), kCFStringEncodingUTF8);
NSString *whatsAppURLString = [NSString stringWithFormat:#"whatsapp://send?text=%#", urlString];
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:whatsAppURLString]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:whatsAppURLString]];
}
else
{
UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Your device has no WhatsApp installed" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[warningAlert show];
}

What is the scheme for calculator?

I'm trying to open the app "Calculator" but I don't know the Scheme
- (IBAction)btnColetorClick:(id)sender
{
NSString *customURL = #"calculator://";
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:customURL]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:customURL]];
}
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];
}
}
It seems that there is no scheme for the native calculator.
Related:
api for showing native calculator in iOS app
Launch an app from within another (iPhone)
You can try "calc://"
it works on iOS13

How to return back to app from Whatsapp

I tried using this method for sending message on whatsapp from my iOS app.
For text
NSString * msg = #"YOUR MSG";
NSString * urlWhats = [NSString stringWithFormat:#"whatsapp://send?text=%#",msg];
NSURL * whatsappURL = [NSURL URLWithString:[urlWhats stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
}
else {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"WhatsApp not installed." message:#"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
I have 2 questions.
1.) how to get back to the app from Whatsapp.
2.) How to send message or image etc by entering phone number instead of fetching from contacts list.

Is there way to get list of installed app on device, which is able to share and receive text data

Like for sharing text data with Whatsapp code is below.
i want to know all installed apps on device which is able to get text data, like below mention code.
NSString * msg = #"YOUR MSG"; NSString * urlWhats = [NSString stringWithFormat:#"whatsapp://send?text=%#",msg]; NSURL * whatsappURL = [NSURL URLWithString:[urlWhats stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL]; } else {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"WhatsApp not installed." message:#"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show]; }
Sharing text,data with other social app than twitter/facebook. You can try the code below :
NSString *shareString = #"text...";
UIImage *shareImage = [UIImage imageNamed:#"image.png"];
NSURL *shareUrl = [NSURL URLWithString:#"http://www.test.com"];
NSArray *activityItems = [NSArray arrayWithObjects:shareString, shareImage, shareUrl, nil];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:activityViewController animated:YES completion:nil];
It will display activity view showing all other text sharing app.
Or You can also create your custom UIActivity also.
In your custom UIActivity subclass you have to simply override one method:
+ (UIActivityCategory)activityCategory
{
return UIActivityCategoryShare;
}
There is UIActivityViewController to list all apps, where you can share your text. And you can customize the list via "More" option there. Also apps having share extension will automatically lists there.

Calling an app from within my app does not work

I have the following code:
NSString *customURL = #"photo://";
NSURL *url = [NSURL URLWithString:customURL];
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:customURL]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:customURL]];
}
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];
}
Which is trying to open iPhoto app by using the custom URL. But the code returns error message and iPhoto is not launched. Any idea why this is?
Thank you for your help.
photo:// doesn't seem to be a supported url.
https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007899-CH1-SW1

Resources