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
}
Related
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.
When i share a video using the UIActivityViewController, the twitter post does not show the video. However, if it take the same video and post it using the twitter app, the video shows and plays embedded in the post.
I am using this code:
MyActivityItemProvider * videoItem = [[MyActivityItemProvider alloc] initWithPlaceholderItem:#""];
NSArray * activityItems = [NSArray arrayWithObjects:
videoItem,
nil];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc]
initWithActivityItems:activityItems
applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];
And in MyActivityItemProvider, I have this:
#implementation MyActivityItemProvider
- (MyActivityItemProvider * )initWithPlaceholderItem:(NSString *)placeholderItem
{
self = [super initWithPlaceholderItem:placeholderItem];
return self;
}
- (id)item
{
NSString * path = [[NSBundle mainBundle] pathForResource:#"video_name" ofType:#"mp4"];
NSURL * fileURL = [NSURL fileURLWithPath:path];
return fileURL;
}
#end
Is it possible for a twitter video post to have the video embedded in it (as if I posted it using the twitter app) when posting using the UIActivityViewController?? Any suggestions on how to achieve this (what it looks) rather simple task?
The video is .mp4 and it is 3.1 MB (like I said, appears to post just fine using the Twitter app and I can send the video via txt message fine).
Video cannot be shared with UIActivityViewController.
Thanks to the uploading media new API, you can share video to twitter by it. And I have tried it, it works.
Please check this: https://github.com/liu044100/SocialVideoHelper
You just need to call this class method.
+(void)uploadTwitterVideo:(NSData*)videoData comment:(NSString*)comment account:(ACAccount*)account withCompletion:(VideoUploadCompletion)completion;
Try this :
+ (void)shareOnTwiiterFromView:(UIViewController *)vc userTitle:(NSString *)title shareURL:(NSString *)urlString
{
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:
SLServiceTypeTwitter];
tweetSheet.completionHandler = ^(SLComposeViewControllerResult result)
{
switch(result)
{
case SLComposeViewControllerResultCancelled:
break;
case SLComposeViewControllerResultDone:
break;
}
};
NSString *twTitle = [NSString stringWithFormat:#"%# %#",title,#"Your App Name"];
[tweetSheet setInitialText:twTitle];
if (![tweetSheet addURL:[NSURL URLWithString:urlString]])
{
NSLog(#"Unable to add the URL!");
}
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
UIPresentationController *control = tweetSheet.presentationController;
[tweetSheet setModalPresentationStyle:UIModalPresentationFormSheet];
[vc presentViewController:control.presentedViewController animated:YES completion:^
{
NSLog(#"Tweet sheet has been presented.");
}];
}
else
{
[vc presentViewController:tweetSheet animated:NO completion:^
{
NSLog(#"Tweet sheet has been presented.");
}];
}
}
else
{
[APP_DEL showErrorAlert:#"No Twitter Account" description:#"There are no twitter accounts configured. You can add or create a Twitter account in Settings."];
}
}
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];
}
Include facebook, twitter, message, email and so on ,like this:
In your ViewController.m :
NSString *message = #"The Flyer http://flyerdream.tumblr.com";
UIImage *image = [UIImage imageNamed:#"flyer"];
NSArray *arrayOfActivityItems = [NSArray arrayWithObjects:message, image, nil];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]
initWithActivityItems:arrayOfActivityItems applicationActivities:nil];
[self.navigationController presentViewController:activityVC animated:YES completion:nil];
I have seen this format (Image shown below) of share option in most of the iOS applications that support iOS 7.
Is there a default code/framework available to implement this share option as it is shown in the image below?
What you are looking for is the UIActivityViewController.
Since you asked a general question I can't do more than give you a link to the documentation
In addition to the accepted answer, a small piece of example code
- (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, leave the things that you don't want to share at nil.
[self shareText:#"Hello world" andImage:nil andUrl:nil];
The Controller in the image you posted is the UIActivitiyViewController this is a link to the class documentation
some good example code:
How to display the default iOS 6 share action sheet with available share options?
I know this question is particular to iOS 7, and the code example specifies iOS 6, but AFAICT they are very similar one might find the example code as helpful as I did.
UIActivityViewController is what you are looking for.
You can specify either the items or the applications
UIActivityViewController *actCont = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
Just use following code for Default Sharing. You can able to add more items into shareItems array as per your requirement.
NSMutableArray *shareItems = [[NSMutableArray alloc] initWithObjects:
#"Hello",
[UIImage imageNamed:#"your_image.png"],
#"http://google.com/", nil];
[self shareItemToOtherApp:shareItems];
Following method is for default sharing Text or Image into other Apps:-
-(void)shareItemToOtherApp:(NSMutableArray *)shareItems{
UIActivityViewController *shareController = [[UIActivityViewController alloc]
initWithActivityItems: shareItems applicationActivities :nil];
[shareController setValue:#"Sharing" forKey:#"subject"];
shareController.excludedActivityTypes = #[UIActivityTypePostToWeibo, UIActivityTypeAssignToContact, UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeSaveToCameraRoll];
shareController.completionHandler = ^(NSString *activityType, BOOL completed)
{
//NSLog(#" activityType: %#", activityType);
//NSLog(#" completed: %i", completed);
};
[self presentViewController: shareController animated: YES completion: nil];
}
If you want to make Custom Sharing sheet then use following code. For this, you have to import <Social/Social.h> framework.
-(void)shareOnFacebook:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *faceSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
// NSLog(#"%#", messageField.text);//This returns the appropriate string
[faceSheet setInitialText:#"Hellooooooo"];
//The facebook VC appears, but initial text is not set to messageField.text
[self presentViewController:faceSheet animated:YES completion:nil];
}
else
{
NSLog(#"Please first install Application and login in Facebook");
}
}
-(void)shareOnTwitter:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"Hello"];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
else{
NSLog(#"Please first install Application and login in Twitter");
}
}
Hope, this is what you're looking for. Any concern get back to me. :)