Facebook Messenger not showing up with UIActivityViewController - ios

I am using UIActivityViewController in my app to provide options for users to share some text.
Apps like facebook, twitter, whatsapp once installed they automatically show up as options with UIActivityViewController, but not Facebook Messenger.
Any special set up I need to do with Messenger? I am using objective c.

According to: Can't share text to fb messenger using UIActivityViewController
In order to make Facebook Messenger appear you need to insert NSURL into UIActivityViewController activityItems
NSURL *url = [NSURL URLWithString:#"http://www.google.com"];
NSArray *activityItems = #[url];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];

Related

Share options application link in IOS

I have a share button in my app on which when user click it shows a popup message to share the link of my application to different social sites, but when u click it shows only Facebook icon to share the link.How can I get different other sites access like Gmail, Twitter, Instagram, Yahoo and WhatsApp. This is my code
NSString *texttoshare = #"myURL"; //this is your text string to share
NSArray *activityItems = #[texttoshare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact, UIActivityTypePrint];
[self presentViewController:activityVC animated:TRUE completion:nil];

Is there a way to share text on facebook messenger without SDK?

Is there a way to share text on facebook messenger without SDK?
I found the following method.
-(void)shareAction:(NSString *)str param:(NSString *)strTitle
{
NSString *title = strTitle;
NSURL *url = [[NSURL alloc]initWithString:str];
NSArray *postItems = #[title, url];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]
initWithActivityItems:postItems
applicationActivities:nil];
activityVC.excludedActivityTypes = #[];
[self presentViewController:activityVC animated:YES completion:nil];
}
However, not just how to select Facebook Messenger among the various apps,
I want to send it directly to Facebook Messenger.
Is there a way without the SDK?
You can use UIActivityViewController to share the app using Facebook Messenger. Please check following sample URL which will display the App list which have implemented share extension.
http://pinkstone.co.uk/how-to-share-things-with-a-uiactivityviewcontroller/

Show all options in UIActivityViewController

I have some trouble with create native share dialog.
My goal is share link of my product by native view controller, but I can't do it. I'm trying test code:
NSURL *google = [NSURL URLWithString:#"http://google.com"];
NSArray *activityItems = #[google];
UIActivity *activity = [UIActivity new];
UIActivityViewController *activityViewControntroller = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:#[activity]];
activityViewControntroller.excludedActivityTypes = #[];
[self presentViewController:activityViewControntroller animated:true completion:nil];
And I get no FB and twitter icons. In the other hand, I can see it in safari both icons and when I'm touching it I see "You need configure your account before post".
So, I want the same behavior: icons for all most-popular social networks such as VK, FB, twitter; messengers like whatsapp, viber and telegram. If some of them is not installed I want dialog "You have to log in before" and redirect to safari (e.g. for FB) to log in or open appstore (e.g. for telegram or viber) to install; otherwise I want post message with my link.
I see it like this: exclude all types from activity vc, than forcibly add all icons I need and check each of them on click manually. But in apple docs I've read that "you have to use native behavior for native items instead of create custom". So, will it be correct? Or there are other ways to solve this?
Try this
-(void)clickShare:(UIButton *)sender{
NSArray * activityItems = #[[NSString stringWithFormat:#"Some initial text."], [NSURL URLWithString:#"http://www.google.com"]];
NSArray * applicationActivities = nil;
NSArray * excludeActivities = #[];
UIActivityViewController * activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
activityController.excludedActivityTypes = excludeActivities;
[self presentViewController:activityController animated:YES completion:nil];
}
this code working in my project.

How to embed a URL in a string while posting on Facebook using UIActivityViewController?

I want to share a URL on Facebook and Twitter using UIActivityViewController. The problem is the URL is very long. Can I give a hyperlink or shorten it somehow?
You can share URL itself the following way
NSURL *longURL = [NSURL URLWithString:#"http://..."];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[ longURL ] applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];

UIActivityController behaviour different on device and simulator

I add an activityViewController to my app like below, passing in an image
UIActivityViewController *avc = [[UIActivityViewController alloc]initWithActivityItems:[NSArray arrayWithObjects:img,nil] applicationActivities:[NSArray arrayWithObjects:nil]];
[self presentModalViewController:avc animated:YES];
[avc release];
On the simulator (twitter, facebook and weibo accounts all not configured):
options mail, twitter, facebook, weibo, assign to contact, save to camera roll, print, and copy appear by default.
but on device:
in my app: twitter, facebook and weibo only show if the accounts are configured.
in safari: twitter, facebook and weibo options are available irregardless of whether the accounts are configured.
I am expecting the same behaviour in my app as safari. am I missing a particular step?
Okay I have figured the problem.
The options shown in the UIActivityViewController totally depends on the type of items that are to be shared. For example, if there is a video, it will not show Facebook or twitter option. But if it's an image and title, it definitely will show the relevant options.
The following will show up apps like mail, twitter, Facebook, assignToContact, save to camera roll, print, copy, etc
// Create the content
NSString *message = #"The Upcoming App Scribble Talk";
UIImage *imageToShare = [UIImage imageNamed:#"createbtn.png"];
NSArray *objectsToShare = [NSArray arrayWithObjects:message, image, nil];
However, the following shall bring up only camera roll, mail or copy.
NSString *message = #"The Upcoming App Scribble Talk";
NSString *videoToShare = #"myFirsScribble.mov";
NSURL *videoPath = [NSURL fileURLWithPath:videoToShare];
NSArray *objectsToShare = [NSArray arrayWithObjects:message, videoPath, nil];
I think you want to show some certain service only in your UIActivityViewController. You may one property called excludedActivityTypes to be defined as below to avoid some default activity.
UIActivityViewController *yourvc = [[UIActivityViewController alloc]initWithActivityItems:[NSArray arrayWithObjects:img,nil] applicationActivities:[NSArray arrayWithObjects:nil]];
yourvc.excludedActivityTypes = #[UIActivityTypePostToWeibo,UIActivityTypePrint,UIActivityTypeMail,UIActivityTypeCopyToPasteboard];//Try this code in simulator.. you can only see FB & Twitter.
[self presentModalViewController:yourvc animated:YES];
[avc release];
likewise you can excluded from default UIActivityViewController..

Resources