Facebook send dialog in iOS app - ios

I have an iOs app in which I tell the user to share a link with the friends he wants. I want to offer him the possibility to open a new inbox from within the app and if possible with pre-filled content. But no pre-filled recipient. And I want it to be available to all users (not only those with facebook connect).
Basically I want to replicate the following send dialog for web in the app: https://developers.facebook.com/docs/reference/dialogs/send/
Which means it will open the facebook app and not the browser to show the new inbox dialog.
From my research I found no clear solution and as it is possible from a website I would be surprised I cannot do the same with the app.
Thank you very much in advance,
Jules

You can use UIActivityViewController.
You first have to create a list of the things you want to share: an URL, a string, etc like this
NSArray *activityItems = #[[NSURL URLWithString:#"www.link-to-share.com], #"What you want written above"];
Afterwards, you just have to create the UIActivityViewController with the things you want to share and present it modally:
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityController animated:YES completion:nil];
You can also add a completion block so that you are notified when the user is done with the sharing:
[activityController setCompletionHandler:^(NSString *activityType, BOOL completed){
//do stuff
}];

Related

iOS 8&9 iPad Share via Twitter using UIActivityViewController dialog closes with viewServiceDidTerminateWithError within 60 seconds

When sharing via the UIActivityViewController using Twitter on some urls the Twitter share dialog will show and then hide if the user does not press post fast enough. This can be reproduced on iPad devices NOT in the Simulator. A quick example is easily shown using the Google Chrome app.
On an iPad Open Google Chrome
Open the URL http://www.telegraph.co.uk/news/worldnews/middleeast/syria/11846382/Russia-is-building-military-base-in-Syria.html
Click on the share button
Select Twitter
The Twitter Dialog pops up, now wait 60 seconds. NOTICE that the Twitter Dialog disappears before the user can press post. Also the image on the right never populates.
An error is logged to the console:
viewServiceDidTerminateWithError:: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "(null)" UserInfo {Message=Service Connection Interrupted}
plugin com.apple.share.Twitter.post interrupted
plugin com.apple.share.Twitter.post invalidated
Repeat steps 2-5 with the URL http://apnews.myway.com/article/20150905/ml--syria-7872368035.html
6. NOTICE that after 60+ seconds the dialog is still up, and the image to the right has been resolved to a glimpse of the webpage. I think there is some problem on iPads where Twitter cannot resolve some URLs.
Repeat steps 2-5 on an iPhone 5 with original URL http://www.telegraph.co.uk/news/worldnews/middleeast/syria/11846382/Russia-is-building-military-base-in-Syria.html
6. NOTICE that after 60+ seconds the dialog is still up, and the image to the right has been resolved to a glimpse of the webpage. On the iPad this same URL did not, I think that is part of the problem.
Code I am using to share in my app:
NSArray *myUrlArray = [[NSArray alloc] init];
NSURL *myUrl = [[NSURL alloc] initWithString:[NSString stringWithFormat:#"%#", #"http://www.telegraph.co.uk/news/worldnews/middleeast/syria/11846382/Russia-is-building-military-base-in-Syria.html"]];
myUrlArray = #[myUrl];
NSMutableArray *applicationActivities = [[NSMutableArray alloc] initWithArray:myUrlArray];
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:myUrlArray applicationActivities:applicationActivities];
[controller setCompletionWithItemsHandler:
^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
NSLog(#"Completed: %#", completed ? #"YES" : #"NO");
if(completed){
// Do Something
}
}];
NSArray *excludedActivities = #[UIActivityTypePostToWeibo,UIActivityTypePrint,
UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll,
UIActivityTypePostToFlickr,UIActivityTypePostToVimeo,
UIActivityTypePostToTencentWeibo, UIActivityTypeAirDrop];
controller.excludedActivityTypes = excludedActivities;
controller.popoverPresentationController.barButtonItem = //Add an anchor to a button bar item on your screen;
[self presentViewController:controller animated:YES completion:nil];
Has anyone else run into this issue when using the UIActivityViewController to share via Twitter, right now the only solution I can come up with is to make my own Twitter share activity and to use that instead of the built in Twitter one. I would really prefer to use the built in Twitter one though.
UPDATE: If I Pass in a UIImage as the second item in the array then this issue does not occur. It seems to be an issue with how Twitter generates an image from a passed in URL. My current plan is to just make the UIImage of the webview myself and pass that to the Twitter share button so that it does not rely on Apple/Twitter to generate the image.
The fact that this is happening in multiple apps strongly suggests that it isn't a problem in your app, and you need to let Apple know what's going on as soon as possible so that they can fix it.
But because I didn't want to leave you with such a short answer, I'll elaborate on it in the form of a song:
If the operating system's broken,
and there's someone you feel like chokin',
don't give the engineer a hug;
file a bug, file a bug, file a bug.
If the sharing service crashes,
and all your hopes, it dashes,
don't stomp your phone into the rug;
file a bug, file a bug, file a bug.
When you find a good workaround,
how you hate bugreporter's UI,
but if your Radar's really sound,
they'll fix it before the pigs fly!
So when you see such bad behavior,
and you really need a savior,
don't ask your question with a shrug;
file a bug, file a bug, file a bug!
File a bug, file a bug, file a buuuuuug!
[At bugreporter dot apple dot coooooom]
Thank you. I'll be here all night.

iOS Share sheet : facebook twitter not present. Only Message and Email present

For Share sheet for my iOS app. As I referred in this link How to display the default iOS 6 share action sheet with available share options?.
And I end up with below working code :
NSString *string = #"Some text to share";
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[string]
applicationActivities:nil];
[self presentViewController:activityViewController
animated:YES
completion:^{
NSLog(#"complerted.");
}];
But I can see only Email & Message button !!?
How can I get other social media buttons in Share sheet like Facebook , twitter as seen below. Even though user account not available/created in device? (As we can see iOS default Photos app, where the share sheet has social buttons even though for example facebook not installed in the device!) Should I enable or extend extension?
Please help,
Thanks & Regards,
//Update
- I added iOS-8 social framework and imported #import <Social/Social.h>.
This UIactivityController show the app which can share your string or image. If you have not added any Facebook or twitter account than that will not show that app in this action sheet.
Try by adding Facebook and twitter account in your devices setting. you will able to see that app too.
You have a More button in your share sheet. Tap on it & it will shows all the available Extension & turn on it for Facebook & Twitter.

UIActivityViewController when have no Facebook account in settings

I'm using UIActivityViewController, I want to show Facebook option even if the user has not defined a Facebook account in device settings.
In my code, Facebook option not shown when there is no Facebook acoount in settings.
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
But, in Safari or more apps there is Facebook option and when click on it - a alert is displayed with "No facebbok account" title and message says "go to settings".
There is any way to add Facebook like this or this possible just for apple apps?
There's no way to do that using UIActivityViewController. If you check other apps (no apple development) you can see that doesn't use UIActivityViewController but Action Sheets or something else and uses Social Framework. You can check this answer. And check this tutorial if you use Social Framework.
Hope it helps!

So, where's that Flickr integration in iOS 7 and what API do I use?

I'm pretty desperate by now -- I can easily upload images to Twitter, Facebook, E-Mail, SMS etc. using very simple APIs.
However, I can't find any information what APIs to use for Flickr uploads.
There's a bunch of libraries that do it, but I thought it was "deeply integrated" into iOS 7 and all I'd need would... basically... be... a... "FRComposeViewController"? ;-)
You need to share your items using the UIActivityViewController to take advantage of flickr sharing.
UIActivityViewController * controller = [[UIActivityViewController alloc] initWithActivityItems:#[image, message] applicationActivities:nil];
[self presentViewController:controller
animated:YES
completion:^{
}];
Is all you need to do, where image is your UIImage instance and message can be an optional NSString instance.
The flickr sharing is a bit buried all the way over on the left...
UIActivity's UIActivityTypePostToFlickr object "posts the provided image to the user’s Flickr account".
Is this what you're looking for?

UIActivityViewController Flickr Sharing - No Flickr option appears

I am trying to use the UIActivityViewController Flickr sharing in iOS 7 but the Flickr icon does not appear in the sharing sheet. I feel like I am missing something basic.
I am testing on an iPhone 5S.
I am logged into a Flickr account on the device.
The same share sheet displays and shares properly with Facebook, Twitter, Email , MMS, and AirDrop.
The photos app on the device displays the Flickr icon in the photos app sharing sheet and can share successfully to the phone Flickr account.
I am sure that I am not listing Flickr in the excluded activities for the UIActivityViewController.
I have tried with both standard UIActivityViewController and the RDActivityViewController subclasses.
Is there something additional required for Flickr sharing? or could someone confirm that they have seen this work in their own app.
Thanks
Flickr share with UIActivityViewController will only work if you are sharing a image.
So in your array with activity items there should be at least one image.
Make sure that the image is of type UIImage:
NSArray *shareItems = #[someImage, #"Text of the messages"];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:shareItems applicationActivities:nil];
Exmple of how it looks: https://www.dropbox.com/s/jpjmnuqbktqgb8s/FlickTest.png

Resources