UIActivityViewController won't share xlsx file - ios

I'm trying to share and XLSX via email using UIActivityViewController but when it just opens an empty email with no attachments.
When I try to add PDF and XLSX files - it opens an email with the PDF file attached - but no XLSX file...
Here's the code:
NSMutableArray *itemsToShare = [[NSMutableArray alloc] init];
[itemsToShare addObject:pdfNSDATA];
[itemsToShare addObject:xlsxNSDATA];
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
[self presentViewController:controller animated:YES completion:nil];

Try inserting the items as file URLs to your array like so:
NSURL *urlToPDF = [NSURL fileURLWithPath:pathToPDF]; //pathToPDF is an nsstring with a path to your file
NSURL *urlToXSLX = [NSURL fileURLWithPath:pathToXSLX]; //So is
NSMutableArray *itemsToShare = [[NSMutableArray alloc] init];
[itemsToShare addObject:urlToPDF];
[itemsToShare addObject:urlToXSLX];
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
[self presentViewController:controller animated:YES completion:nil];
Of course you'll need to save the NSData to the file system in order to be able to do this. You can use NSData's writeToURL:atomically to achieve this.

Related

Sending user location to whatsapp and facebook

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

Sharing link in twitter with a preview iOS?

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
}

UIActivityViewController - Facebook/Twitter not showing in iOS Simulator

I've set up my UIActivityViewController and mail shows up. But I can't figure out how to get Facebook/Twitter to work? I have read somewhere that since obviously the Xcode doesn't have Facebook/Twitter signed in, iOS7 doesn't show the app?
My code:
NSArray *activityItems = #[#"Hello"];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityViewController.excludedActivityTypes = #[UIActivityTypePostToWeibo, UIActivityTypeAssignToContact ];
[self presentViewController:activityViewController animated:YES completion:NULL];

iOS how to implement the official share function

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

UIActivityViewController Messenger not working on iOS Simulator

I'm getting the following result when I try to initialize the Messenger component of UIActivityViewController:
I'm using this code to instantiate my UIActivityViewController:
NSString *textToShare = #"Text that will be shared";
NSArray *itemsToShare = [[NSArray alloc] initWithObjects:textToShare, nil];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.excludedActivityTypes = [[NSArray alloc] initWithObjects: UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, UIActivityTypePostToWeibo,UIActivityTypePostToFacebook,UIActivityTypePostToTwitter, nil];
[activityVC setValue:#"My Subject Text" forKey:#"subject"];
[self presentViewController:activityVC animated:YES completion:nil];
I then get the following error in my logs when I attempt to send with Message
Launch Services: Unable to find app identifier com.apple.MobileSMS
2013-07-31 01:27:15.180 Coolist[54111:c07] Application tried to push a nil view controller on target <MFMessageComposeViewController: 0xa38db30>.
Is this just a simulator problem?

Resources