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:)];
Related
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.
I've a problem with the UIActivityController on iOS 8 iPad: the activity view works correctly I can select a share service (i.e. Twitter) but when the "publish" view appear I can only click on the Post button,the Cancel button doesn't work. I've the same problem on real devices and on the simulator.
If you have an idea about how to fix this problem,...
Thanks
Here's my code:
- (IBAction)activityController:(id)sender {
// items to share
NSURL *url = [NSURL URLWithString:_articleUrl];
NSArray *items=#[url];
// create the controller
UIActivityViewController *controller = [[UIActivityViewController alloc]initWithActivityItems:items applicationActivities:nil];
[self presentViewController:controller animated:YES completion:nil];
UIPopoverPresentationController *popPC = controller.popoverPresentationController;
popPC.barButtonItem = _buttn;
popPC.permittedArrowDirections = UIPopoverArrowDirectionAny;
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.
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];
}
I want to save a photo with the same options given by the default iPhone photo app as seen in this picture:
You can do this using UIActivityViewController. You can create a UIActivityViewController, pass it an image, or the URL to an image, and optionally tell it to exclude certain activities that you don't want to appear. Then, present it, as you would any other viewController.
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[ myImage ] applicationActivities:nil];
activityViewController.excludedActivityTypes = #[ UIActivityTypeAssignToContact ];
activityViewController.completionHandler = ^(NSString *activityType, BOOL completed){
// handle completion
};
[self presentViewController:activityViewController animated:YES completion:nil];
Check out the documentation for more info.