ios - UIActivityViewController: SMS option not showing - ios

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

Related

How to share Animated gif

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];

objective-c share image to Instagram from my iOS application

I've spent a long time searching how to share photo from iOS application to Instagram. Other social media like Twitter are working fine. I have found a lot of resources on Google but it's not working.
Please I need some help to add Instagram share button to the UIActivityViewController that already has Twitter share button.
Here is my code:
- (IBAction)shareBtnClicked {
NSString *textToShare = #"Share \r";
NSURL *url = newsC.URL;
NSArray *objectsToShare = #[textToShare, url];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
//this array should add the activities that I don’t want
NSArray *excludeActivities = #[ UIActivityTypePrint,
UIActivityTypeAssignToContact,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo
];
activityVC.excludedActivityTypes = excludeActivities;
[self presentViewController:activityVC animated:YES completion:nil];
Thanks in advance
You need to use below method:
-(void)instaPostImage
{
NSURL *myURL = [NSURL URLWithString:#"Your image url"];
NSData * imageData = [[NSData alloc] initWithContentsOfURL:myURL];
UIImage *imgShare = [[UIImage alloc] initWithData:imageData];
NSURL *instagramURL = [NSURL URLWithString:#"instagram://app"];
if([[UIApplication sharedApplication] canOpenURL:instagramURL]) //check for App is install or not
{
UIImage *imageToUse = imgShare;
NSString *documentDirectory=[NSHomeDirectory() stringByAppendingPathComponent:#"Documents"];
NSString *saveImagePath=[documentDirectory stringByAppendingPathComponent:#"Image.png"];
NSData *imageData=UIImagePNGRepresentation(imageToUse);
[imageData writeToFile:saveImagePath atomically:YES];
NSURL *imageURL=[NSURL fileURLWithPath:saveImagePath];
self.documentController=[[UIDocumentInteractionController alloc]init];
self.documentController = [UIDocumentInteractionController interactionControllerWithURL:imageURL];
self.documentController.delegate = self;
self.documentController.annotation = [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:#"Testing"], #"InstagramCaption", nil];
self.documentController.UTI = #"com.instagram.exclusivegram";
UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController;
[self.documentController presentOpenInMenuFromRect:CGRectMake(1, 1, 1, 1) inView:vc.view animated:YES];
}
else {
DisplayAlertWithTitle(#"Instagram not found", #"")
}
}
Try This
- (IBAction)shareBtnClicked {
NSString *textToShare = #"Share \r";
NSURL *url = newsC.URL;
NSData * imageData = [[NSData alloc] initWithContentsOfURL:url];
UIImage *imgShare = [[UIImage alloc] initWithData:imageData];
NSArray *objectsToShare = #[imgShare, textToShare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
//this array should add the activities that I don’t want
NSArray *excludeActivities = #[ UIActivityTypePrint,
UIActivityTypeAssignToContact,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo
];
activityVC.excludedActivityTypes = excludeActivities;
[self presentViewController:activityVC animated:YES completion:nil];
}

Share PDF file on iOS

I Would like to know if i could use UIActivityViewController so i can share a PDF file by email, or message, or other means possible.
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:linkToProspect]];
This is my PDF data that i would like to share.
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:*NSARRAY* applicationActivities:nil];
[self presentViewController:controller animated:YES completion:nil];
And this is the way i would like to do it.
Is there such a way ? Or should i create something custom ?
// pathToPDF should be a full path to your PDF file
NSString *pathToPDF = [[NSBundle mainBundle] pathForResource:#"ReadMe" ofType:#"pdf"];
NSURL *urlToPDF = [NSURL fileURLWithPath:pathToPDF];
NSMutableArray *itemsToShare = [[NSMutableArray alloc] init];
[itemsToShare addObject:urlToPDF];
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
[self presentViewController:controller animated:YES completion:nil];

Twitter icon not showing on uiactivitycontroller in ios 7

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];

UIActivityViewController strange behaviour in iOS 7

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.

Resources