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];
}
Related
- (IBAction)postToInstagram:(id)sender {
NSURL *instagramURL = [NSURL URLWithString:#"instagram://app"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
{
CGRect rect = CGRectMake(0,0,0,0);
NSString *jpgPath=[NSHomeDirectory() stringByAppendingPathComponent:#"Documents/Home_1_instgram.igo"];
UIImage *imageN = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:#"%#", jpgPath]];
// [UIImagePNGRepresentation(_imageDetail.image) writeToFile:jpgPath atomically:YES];
NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:#"file://%#",jpgPath]];
self.documentController.UTI = #"com.instagram.exclusivegram";
self.documentController = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
NSString *caption = self.catalogueImage.caption; //settext as Default Caption
//Removing pre-filled captions from mobile sharing
//http://developers.instagram.com/post/125972775561/removing-pre-filled-captions-from-mobile-sharing
self.documentController.annotation = [NSDictionary dictionaryWithObject:#"Here Give what you want to share" forKey:#"InstagramCaption"];
NSLog(#"caption: %#",caption);
[self.documentController presentOpenInMenuFromRect: rect inView: self.view animated: YES ];
}
else
{
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"INSTAGRAM NOT FOUND" message:#"Please install instagram to post to instagram." delegate:nil cancelButtonTitle:nil otherButtonTitles:#"ok", nil];
[alert show];
}
}
I found the solution to it. In iOS Instagram directly sends user to the filter section whereas in android the user is directed to the crop section. It was mentioned in Instagram iPhone Hook.
Thank You
i have changed something in your code :
you should use com.instagram.photo
- (IBAction)postToInstagram:(id)sender {
if ([self schemeAvailable:#"instagram://app"])
{
CGRect rect = CGRectMake(0,0,0,0);
NSString *jpgPath=[NSHomeDirectory() stringByAppendingPathComponent:#"Documents/Home_1_instgram.igo"];
UIImage *imageN = [UIImage imageNamed:#"IMG_1304.PNG"];
[UIImagePNGRepresentation(imageN) writeToFile:jpgPath atomically:YES];
NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:#"file://%#",jpgPath]];
self.documentController.UTI = #"com.instagram.photo";
self.documentController = [UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
NSString *caption = #"YourCaption"; //settext as Default Caption
//Removing pre-filled captions from mobile sharing
//http://developers.instagram.com/post/125972775561/removing-pre-filled-captions-from-mobile-sharing
self.documentController.annotation = [NSDictionary dictionaryWithObject:#"Here Give what you want to share" forKey:#"InstagramCaption"];
NSLog(#"caption: %#",caption);
[self.documentController presentOpenInMenuFromRect: rect inView: self.view animated: YES ];
}
else
{
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"INSTAGRAM NOT FOUND" message:#"Please install instagram to post to instagram." delegate:nil cancelButtonTitle:nil otherButtonTitles:#"ok", nil];
[alert show];
}
}
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];
}
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.
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.
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