using a simple UIActivityViewController
-(void)share{
NSString *textToShare = _mytext;
NSURL *url = [NSURL URLWithString:#"http://www.google.com"];
UIImage *imageToShare = _myimage;
NSArray *activityItems = #[textToShare, url, imageToShare];
UIActivityViewController *activityVC =
[[UIActivityViewController alloc] initWithActivityItems:activityItems
applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
}
I want to share a text, url and image where appropriate.
So if the user chooses mail, everything appears. Etc with the rest of the apps (pinterest, facebook, twitter)
On Facebook Messenger - If a url and an image is shared, the share screen crashes. Is this a known issue (can't send image with a url)?
* EDIT: Updated to the latest SDK
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentTitle = #"Your title";
content.contentDescription = #"Some description text maybe...";
content.contentURL = [NSURL URLWithString:#"http://yourlink.com"];
content.imageURL = [NSURL URLWithString:#"http://yourlink.com/theImage.png"];
[FBSDKMessageDialog showWithContent:content delegate:self];
// Delegate
- (void)sharer: (id<FBSDKSharing>)sharer didCompleteWithResults: (NSDictionary *)results
{
BOOL complete = [[results valueForKeyPath:#"didComplete"] boolValue];
NSString *completionGesture = [results valueForKeyPath:#"completionGesture"];
if (completionGesture && [completionGesture isEqualToString:#"cancel"]) {
// action was canceled by the user
}
if (complete) {
// the message/link/image was sent
}
}
- (void) sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
// handle error...
}
You can give it a try :)
Related
Please Help us..
We want to share projects (i.e. Its Images, text and also my app url).
But i can't get SDK to share all on whatsApp, facebook, twitter, mails and messages. same as android developer using Intent called ACTION_SEND
Try this -
- (void)shareText:(NSString *)text andImage:(UIImage *)image andUrl:(NSURL *)url
{
NSMutableArray *sharingItems = [NSMutableArray new];
if (text) {
[sharingItems addObject:text];
}
if (image) {
[sharingItems addObject:image];
}
if (url) {
[sharingItems addObject:url];
}
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];
[self presentViewController:activityController animated:YES completion:nil];
}
Call shareText like this -
[self shareText:#"Your text" andImage:nil andUrl:nil];
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
imageUser.hidden=NO;
// [imageUser sendSubviewToBack:_horizontalScrollView];
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
UIImage *goImage=[[UIImage alloc]init];
goImage=[self scaleImage:image123];
[controller setInitialText:#"Check out my pic from "];
[controller addURL:[NSURL URLWithString:#"www.awesomeapp.com"]];
[controller addImage:goImage];
imageUser.hidden=YES;
[self presentViewController:controller animated:YES completion:Nil];
}
I have gone through many stackoverflow questions and tried almost all. Some users reported it as bug, If so do we have any other way through which I can achieve my goal. It works like charm when Facebook app is not there but when the app is there this won't work :
[controller addURL:[NSURL URLWithString:#"www.awesomeapp.com"]];
Please help me achieve my goal. Thanks in advance.
I too headed up with is problem,some how i managed with FBSDKShareKit
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"fb://"]]) {
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
NSString * UrlString = [NSString stringWithFormat:#"https://www.google.co.in/"];
NSString * Subject = [NSString stringWithFormat:#"FBSDKShareKit is an alternative to this issue"];
content.contentURL = [NSURL URLWithString:UrlString];
content.contentTitle = #"FBSDKShareKit";
content.contentDescription = Subject;
content.imageURL = [NSURL URLWithString:#"https://i.vimeocdn.com/portrait/58832_300x300.jpg"];
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
dialog.fromViewController = self;
dialog.shareContent = content;
dialog.mode = FBSDKShareDialogModeFeedBrowser;
[dialog show];
}else{
//Go with your own method to share in FaceBook
}
In my pod file:
pod 'FBSDKShareKit', '~> 4.6.0'
dialog.mode = FBSDKShareDialogModeFeedBrowser it opens a fbShareDialog within your app which consist of all given datas.
Try some other alternatives for mode such as FBSDKShareDialogModeShareSheet,FBSDKShareDialogModeBrowser,FBSDKShareDialogModeWeb... it may also help you. I found FBSDKShareDialogModeFeedBrowser as satisfying. Try it,Let me know whether it works or not.
I am trying to send user location to facebook and whatsapp from my app by UIActivityViewController.
- (IBAction)shareUserLocation:(id)sender {
shareArray = [[NSArray alloc]initWithObjects:[NSURL URLWithString:[NSString stringWithFormat:#"http://maps.apple.com/maps?q=%f,%f",location.coordinate.latitude,location.coordinate.longitude]],nil];
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:shareArray applicationActivities:nil];
controller.excludedActivityTypes = #[];
[self presentViewController:controller animated:YES completion:nil];
}
Its working but opening the location in apple maps.
Is there a way I can open the location in Google maps.
P.S- I have not tried whatsApp i have only tested for facebook.
If you want to open a Google Maps URL in your Google Maps iOS app, you can use comgooglemapsurl://maps.google.com/?q=%f,%f. If you want to show it in browser, you can do https://maps.google.com/?q=%f,%f.
Sample code:
-(void)testURL:(CLLocation*)location {
NSArray *shareArray;
if ([[UIApplication sharedApplication] canOpenURL:[[NSURL alloc] initWithString:#"comgooglemaps://"]]) {
shareArray = [[NSArray alloc]initWithObjects:[NSURL URLWithString:[NSString stringWithFormat:#"comgooglemapsurl://maps.google.com/?q=%f,%f",location.coordinate.latitude,location.coordinate.longitude]],nil];
} else {
shareArray = [[NSArray alloc]initWithObjects:[NSURL URLWithString:[NSString stringWithFormat:#"https://maps.google.com/?q=%f,%f",location.coordinate.latitude,location.coordinate.longitude]],nil];
}
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:shareArray applicationActivities:nil];
controller.excludedActivityTypes = #[];
[self presentViewController:controller animated:YES completion:nil];
}
I had an application in which i am sharing a link to twitter using Uiactivityviewcontroller.its just showing the text and link in twitter in my TL.i want it to be shown like as in Facebook with an image extracted from the link.I am doing like this
NSURL *shareUrl = [NSURL URLWithString:#“http://dhdhdh”];
NSString* someText = #“fdfdfd”;
UISimpleTextPrintFormatter *printData = [[UISimpleTextPrintFormatter alloc]
initWithText:#"http://dhdhdh"];
NSArray* dataToShare = #[someText,shareUrl,printData]; // ...or whatever pieces of data you want to share.
NSArray *appActivities = [NSArray arrayWithObjects:[[UrlActivity alloc] init], nil];
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
applicationActivities:appActivities];
activityViewController.excludedActivityTypes=#[UIActivityTypeAddToReadingList,UIActivityTypeAirDrop,UIActivityTypePrint,UIActivityTypeAssignToContact];
// activityViewController.
[self.navigationController presentViewController:activityViewController animated:YES completion:nil];
Can anybody help me on this?
Try this
go to Build settings in targer-> link Binary with Library - > add "Social" framework
Import #import <Social/Social.h>
NSURL *url = [NSURL URLWithString:#"https://upload.wikimedia.org/wikipedia/en/3/38/Avatarjakeneytiri.jpg"];
UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[controller setInitialText:#"myShare"];
[controller addImage:img];
[self presentViewController:controller animated:YES completion:nil];
}
else {
//wont work in simulator
}
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.