In iOS 7 I want to share something it brings up an action sheet similar to this:
my code is:
NSString *textToShare = #"your text";
UIImage *imageToShare = [UIImage imageNamed:#"yourImage.png"];
NSArray *itemsToShare = #[textToShare, imageToShare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll]; //or whichever you don't need
[self presentViewController:activityVC animated:YES completion:nil];
But i'm getting blank like this:
Related
This is my code for sharing gif but i'm not able to share animated gif, i,m getting only image.
NSData *animatedGif = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:fileName]];
NSArray *sharingItems = [NSArray arrayWithObjects: animatedGif, nil];
NSLog(#"%#", sharingItems);
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
i configured twitter properly in setting menu, my problem is only twitter string is showing on UIActivityViewController, can anyone help me how can i display twitter icon?
NSString *shareString = #"Welcome.";
UIImage *shareImage = [UIImage imageNamed:#"welcome.png"];
NSURL *shareUrl = [NSURL URLWithString:#"http://www.welcome.com"];
NSArray *activityItems = [NSArray arrayWithObjects:shareString, shareImage, shareUrl, nil];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
activityViewController.excludedActivityTypes = #[UIActivityTypePostToWeibo, UIActivityTypeAssignToContact];
[self presentViewController:activityViewController animated:YES completion:nil];
I have used UIActivityViewController with share options.
NSURL *url =[NSURL URLWithString:#"google.com"];
UIImage *img = [UIImage imageNamed:#"myImage"];
NSMutableArray *ar2 = [NSMutableArray arrayWithObjects:UIActivityTypePostToWeibo, UIActivityTypeSaveToCameraRoll, UIActivityTypeMessage, UIActivityTypePrint, UIActivityTypeAssignToContact, nil];
NSArray *itemsToShare = #[textToShare,url];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
[activityVC setValue:#"Sample - Share" forKey:#"subject"];
activityVC.excludedActivityTypes = ar2;
[self presentViewController:activityVC animated:YES completion:NULL];
But it is showing with some white view and AirDrop name as "null'. Can anyone suggest me a solution...
I have test you code and it is working fine for me. I am using iPod5 touch and iOS 7.1.2
i have a little suggestion. Try to call your code with a delay. like:
[self performSelector:#selector(shareActivityView) withObject:nil afterDelay:0.5];
Your method shareActivityView seems:
-(void)shareActivityView
{
NSURL *url =[NSURL URLWithString:#"google.com"];
UIImage *img = [UIImage imageNamed:#"myImage"];
NSMutableArray *ar2 = [NSMutableArray arrayWithObjects:UIActivityTypePostToWeibo, UIActivityTypeSaveToCameraRoll, UIActivityTypeMessage, UIActivityTypePrint, UIActivityTypeAssignToContact, nil];
NSArray *itemsToShare = #[textToShare,url];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
[activityVC setValue:#"Sample - Share" forKey:#"subject"];
activityVC.excludedActivityTypes = ar2;
[self presentViewController:activityVC animated:YES completion:NULL];
}
This is weird but sometimes it works.
I'm trying to send a string by using AirDrop. The problem is that I don't know how to use NSURL to send a string from UITextField. How can I share NSString from UITextField by using AirDrop? The following is my IBAction code. However, sending part is failed.
-(IBAction)sendButton:(id)sender {
NSURL *url = [NSURL URLWithString:self.inputTextField.text];
NSArray *objectsToShare = #[url];
//NSLog(#"you type: %#", self.inputTextField.text);
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
// Exclude all activities except AirDrop.
NSArray *excludedActivities = #[UIActivityTypePostToTwitter, UIActivityTypePostToFacebook,
UIActivityTypePostToWeibo,
UIActivityTypeMessage, UIActivityTypeMail,
UIActivityTypePrint, UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo, UIActivityTypePostToTencentWeibo];
controller.excludedActivityTypes = excludedActivities;
// Present the controller
[self presentViewController:controller animated:YES completion:nil];
//[self.readTextView setText:self.inputTextField.text];
}
I am using UIActivityViewController to allow sharing by Mail, Facebook, Twitter and SMS. I have the following code:
-(void) aFunction
{
NSString *textToShare = appRecord.title;
UIImage *imageToShare = [UIImage imageNamed:#"test/png"];
NSURL *url = [NSURL URLWithString:#"http://www.stackoverflow.com"];
NSArray *activityItems = [[NSArray alloc] initWithObjects:textToShare, imageToShare,url,nil];
UIActivity *activity = [[UIActivity alloc] init];
NSArray *applicationActivities = [[NSArray alloc] initWithObjects:activity, nil];
UIActivityViewController *activityVC =
[[UIActivityViewController alloc] initWithActivityItems:activityItems
applicationActivities:applicationActivities];
activityVC.excludedActivityTypes = #[UIActivityTypePostToWeibo, UIActivityTypeAssignToContact, UIActivityTypePrint ,UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll,UIActivityTypeMessage ];
[self presentViewController:activityVC animated:YES completion:nil];
[activityItems release];
[activity release];
[applicationActivities release];
[activity release];
}
The code produces the following:
http://s24.postimg.org/tas3zo9w5/Screen_Shot_2013_10_01_at_5_09_26_PM.png
The SMS option is missing. What I am doing wrong?
you are excluding UIActivityTypeMessage (excludedActivityTypes). This hides the Messages (SMS/iMessage) option