UIActivityViewController called from UITableViewCell incorrectly displayed - ios

I have a UITableView in a UIViewController that is embedded in a Navigation Controller. The UIViewController is arranged using Auto Layout. I am using SWTableViewCell to enable swipe left-to-right. This displays a 'share' button which displays a UIActivityViewController when tapped.
The problem is, the UIActivityViewController displays incorrectly when called, squished to the left side of the view and attached to the top left corner. See images below for example, the first is during display of the UIActivityViewController, and the second is once the UIActivityViewController is displayed.
I haven't been able to find any other posts about this type of issue. The code below is how I call the UIActivityViewController from the - (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerLeftUtilityButtonWithIndex:(NSInteger)index method of SWTableViewCell delegate.
WhatsAppMessage *whatsappMsg = [[WhatsAppMessage alloc] initWithMessage:shareItem forABID:nil];
NSArray *activityItems = #[shareItem, whatsappMsg];
NSArray *applicationActivities = #[[[JBWhatsAppActivity alloc] init],[[LINEActivity alloc] init], [[WeixinTimelineActivity alloc] init],[[WeixinSessionActivity alloc] init]];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
activityViewController.excludedActivityTypes = #[UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, UIActivityTypeAddToReadingList, UIActivityTypePostToVimeo, UIActivityTypePostToFlickr, UIActivityTypeAirDrop];
[self.navigationController presentViewController:activityViewController animated:YES completion:^{}];
Any ideas?

I finally found the answer and I knew it had something to do with auto layout. Earlier in the project I had most of my auto layout constraints set in code and I had put the following line in my AppDelegate.m file:
self.window.translatesAutoresizingMaskIntoConstraints = NO;
After removing this line, the UIActivityViewController loads perfectly!
Hopefully this helps others who run into this issue.

Related

Change activity items base on which application is selected for sharing in iOS

I share an image with text to othe applications.
NSArray *activityItems = #[title, finalImage];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact, UIActivityTypePrint, UIActivityTypePostToTwitter, UIActivityTypePostToWeibo];
[self presentViewController:activityVC animated:TRUE completion:nil];
Problem with this code is that I share title and image for all destination apps. but for instance, WhatsApp has problem when I share image with title. When I delete title it will correctly share the image but when I add title to activityItems, it just sends title. I want to detect if whats app is selected and then just send the image

iOS app Sharing through whatsApp

I am using this code in my app to share a URL to other apps using share extension.
NSArray *activityItems = #[adURL];
UIActivityViewController *activityViewControntroller = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityViewControntroller.excludedActivityTypes = #[];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
activityViewControntroller.popoverPresentationController.sourceView = self.view;
activityViewControntroller.popoverPresentationController.sourceRect = CGRectMake(self.view.bounds.size.width/2, self.view.bounds.size.height/4, 0, 0);
}
[self presentViewController:activityViewControntroller animated:true completion:nil];
When WhatsApp is selected I get a view like this:
Is there any way I can change the color of the right 'Send' button in the navigation bar?
You can set this property on the modal before opening, something like the following
modal.navigationController.navigationBar.barTintColor = ...
This will change the navigationBar color, you can select your app color there,, this will make send button prominent automatically.

creating slide up menu like in iOS 7 Safari's share/bookmark menu

I'd like to create very similar sliding up menu as share/bookmark/copy/paste menu in iOS7 Safari.
What is the best way of building it?
Is there any ready made template in XCode or do I have to follow the same principle as when building the slide left/right hamburger menu?
example action:
-(IBAction)sendPost:(id)sender {
NSArray *activityItems;
activityItems = #[#"example share / copy text"]; //needs to be an array because you //could add pictures additionally
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityController
animated:YES completion:nil];
}

UIActivityViewController: PostToTwitter: text can´t be changed in presented modal View

i have a problem with iOS 6´s UIActivityViewController. I want to share an image and a text.
When i share it via Facebook, the text is editable in the modal view. In Twitter, i can't change the text. is there a way to change it for Twitter, so that the text is editable ?
This is my code:
NSArray *activityItems = #[#"Test Text",resultImage];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact, UIActivityTypePrint, UIActivityTypeCopyToPasteboard,UIActivityTypeMessage,UIActivityTypePostToWeibo];
[self presentViewController:activityVC animated:YES completion:nil];

uiactivityviewcontroller from toolbar

I´m trying to use the following code in my app to get the uiactivityviewcontroller, and it works if I set up a round rect button, but not with a UIBarButtonItem? Am I missing something really simple here?
- (IBAction)shareIt:(id)sender {
NSArray *activityItems;
activityItems = #[_textView.text];
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityController animated:YES completion:nil];
}
I'm guessing (read: I'm sure) that this is happening because you didn't hook up the action to the barButtonItem correctly in code. If you are making it in code, you can use this:
UIBarButtonItem *bBI = ...; //get it
[bBI setTarget:self];
[bBI setAction:#selector(shareIt:)];

Resources