UIActivityViewController not working on iPad? iOS 8 - ios

I've followed suggestions from similar SO questions and can't seem to make this work. I'm working on a game, which reports the last score and then a share button for that last score.
This works on iPhone and my code for the iPad as shown below doesn't. The iPad version just crashes as soon as I hit the Share button. This code was from this tutorial on Coding Explorer.
iPad code (doesn't work)
- (IBAction)shareButton:(id)sender;
{
NSString * text = [NSString stringWithFormat:#"I just scored %li in Flying Freddy. Think you can beat it? https://itunes.apple.com/app/id1033007818", (long)_score];
NSArray *objectsToShare = #[text];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
NSArray *excludeActivities = #[UIActivityTypeAirDrop,
UIActivityTypePrint,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo];
activityVC.excludedActivityTypes = excludeActivities;
[self presentViewController:activityVC animated:YES completion:nil];
}
iPhone code (does work)
- (IBAction)ShareIt {
NSString * text = [NSString stringWithFormat:#"I just scored %li in Flying Freddy. Think you can beat it? https://itunes.apple.com/app/id1033007818", (long)_score];
NSArray * activityItems = #[text];
UIActivityViewController * avc = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
avc.excludedActivityTypes = #[ UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll];
[self presentViewController:avc animated:YES completion:nil];
}

You must add a source view.
Try to add this line :
activityVC.popoverPresentationController.sourceView = self.view;
You can also add the arrow direction :
activityVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionRight;
activityVC.popoverPresentationController.sourceView = sender;

I also had to set the modalPresentationStyle, preferredContentSize and sourceRect for the Pipiks answer to work.

Related

iOS - Is it possible to share UIImage with Programatically text to WhatsApp in iOS?

NSString *texttoshare = #"Hello world....";
UIImage *image = [UIImage imageNamed:#"image.png"]
NSArray *activityItems = #[image,texttoshare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypeAirDrop];
[self presentViewController:activityVC animated:TRUE completion:nil];
You cant share image and text together, but you can convert image and text together has pdf and you can share pdf PDF documents (UTI: com.adobe.pdf)
https://www.whatsapp.com/faq/en/iphone/23559013

How to share the text on WeChat app from my IOS(Objective c) app?

I'm doing the lost of search for sharing the text on WeChat app from my app but I didn't get any proper solution for these.Please help me to solve this issue.
Thanks in advance...
If you have installed WeChat your iPhone use this code
- (IBAction)shareBtnAction:(id)sender
{
NSString *textToShare = #"";
NSURL *myWebsite = [NSURL URLWithString:#"www.facebook.com"];
NSArray *objectsToShare = #[textToShare, myWebsite];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
NSArray *excludeActivities = #[UIActivityTypeAirDrop,
UIActivityTypePrint,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo];
activityVC.excludedActivityTypes = excludeActivities;
[self presentViewController:activityVC animated:YES completion:nil];
}
Try this i hope it would be helpful for you!!!
#IBAction func btnExport(sender: AnyObject)
{
let someText:String = "Hello want to share text also"
let objectsToShare:URL = URL(string: "http://www.google.com")!
let sharedObjects:[AnyObject] = [objectsToShare as AnyObject,someText as AnyObject]
let activityViewController = UIActivityViewController(activityItems : sharedObjects, applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view
activityViewController.excludedActivityTypes = [ UIActivityType.airDrop, UIActivityType.postToFacebook,UIActivityType.postToTwitter,UIActivityType.mail]
self.present(activityViewController, animated: true, completion: nil)
}

iOS share button crashing when run on ipad

I am working on a xcode project in objective-c and i want a share button on my ios application to share things i watched a tutorial on youtube here's the link : https://www.youtube.com/watch?v=zkrOKN_OA_A
but when i run this code on iphone it works properly and when i run this code on ipad the xcode give's me this error :
int main(int argc, char * argv[]) {
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}}
I used this code :
- (IBAction)Share1:(id)sender {
UIImage *shareImage = [UIImage imageNamed:#"invoice_logo.png"];
NSArray *itemsToShare = #[shareImage];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.excludedActivityTypes = #[];
[self presentViewController:activityVC animated:YES completion:nil];}
You are missing :
activityVC.excludedActivityTypes=#[UIActivityTypePostToFacebook,UIActivityTypePostToTwitter]// add your share types
look at the video you provided from 7:30 min
Try this:
UIImage *shareImage = [UIImage imageNamed:#"invoice_logo.png"];
NSArray *itemsToShare = #[shareImage];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]
initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.popoverPresentationController.sourceView = self.view;
activityVC.popoverPresentationController.sourceRect =
CGRectMake(self.view.bounds.size.width / 2.0, self.view.bounds.size.height-50, 1.0, 1.0);
[self presentViewController:activityVC animated:YES completion:nil];

Email issue iOS8 in Simulator

I have an issue in iOS8 issue in Simulator in won't work ? can anybody help me for this ?
here message is String Message but it not appear in Mail sheet ?
Here's what i have tried !!
NSMutableString* sub = [NSMutableString string];
[message appendFormat:#"\n"];
[sub appendString:#"Item Id : "];
[sub appendString:item.item_id];
UIImage *img = self.thumbnailImageView.image;
NSMutableArray *actItems = [[NSMutableArray alloc] init];
[actItems addObject:message];
[actItems addObject:sub];
if(img != nil)
{
[actItems addObject:img];
}
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:actItems
applicationActivities:nil];
activityViewController.excludedActivityTypes = #[UIActivityTypePostToFacebook,
UIActivityTypePostToTwitter,
UIActivityTypeAirDrop];
[self.navigationController presentViewController:activityViewController
animated:YES
completion:^{}];
[activityViewController setValue:sub forKey:#"subject"];
activityViewController.popoverPresentationController.sourceView = parentView;

Add an integer to UIActivityViewController?

I would like to add an integer to a UIActivityViewController, yet it is not working. Here is my code:
- (IBAction)socialButton:(id)sender {
NSString *shareText = #"I just scored %i in Helicave!", scoreNumber;
NSArray *itemsToShare = #[shareText];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypePostToFlickr, UIActivityTypePostToTencentWeibo, UIActivityTypePostToWeibo, UIActivityTypePostToVimeo];
[self presentViewController:activityVC animated:YES completion:nil];
}
This line:
NSString *shareText = #"I just scored %i in Helicave!", scoreNumber;
needs to be:
NSString *shareText = [NSString stringWithFormat:#"I just scored %i in Helicave!", scoreNumber];
Try changing the first line,
NSString *shareText = #"I just scored %i in Helicave!", scoreNumber;
to:
NSString *shareText = [NSString stringWithFormat:#"I just scored %i in Helicave!", scoreNumber];
You need to tell XCode that the string is going to have formatting, like %#, or %i, before you create the string

Resources