I have added an 'UIActivityViewController' this works very well but the "Print" button is not shown.
How can I add the "Print" Button? I will print out the actual PDF file which is shown in an 'UIWebView' named "background".
Perfectly: That not the URL will be sent by email oder post on twitter/facebook special the pdf as Picture
here is my code:
NSArray *items = #[self.background.request.URL.absoluteString];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
activityViewController.completionHandler = ^(NSString *activityType, BOOL completed) {
};
activityViewController.excludedActivityTypes = #[UIActivityTypeCopyToPasteboard];
EDIT:
How Can I print out the actual PDF shown in UIWebView as Image?
And how can I add the Printer Button?
Try to explicitly include a UIActivity of type UIActivityTypePrint in your applicationActivities when initialising the activity view controller.
Related
I have reviewed a bunch of posts here, numerous online tutorials/sample code and I'm stumped. In my app I have no problem displaying the UIActivityController natively provided by iOS7 with the sharing options appropriate to my app (AirDrop and mail).
The specific problem I'm having is getting my saved document attached to the email message when the user selects the option to share via mail. The message body is being set to the text, but the attachment is MIA. The relevant code is:
// Generate the XML file to be shared for the currently displayed record...
NSURL *url = [self createShareFile];
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:#[#"Data shared from my app.", url] applicationActivities:nil];
// Filter out the sharing methods we're not interested in....
controller.excludedActivityTypes = #[UIActivityTypePostToTwitter, UIActivityTypePostToFacebook,
UIActivityTypePostToWeibo,
UIActivityTypeMessage,
UIActivityTypePrint, UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo, UIActivityTypePostToTencentWeibo];
// Now display the sharing view controller.
[self presentViewController:controller animated:YES completion:nil];
What am I missing? My file is being properly created, the contents is correct and the NSURL object contains the proper path to the file.
Thanks!
Problem solved.....
The code posted in my original post is 100% accurate. The issue ended up being in the way I was constructing the NSURL being returned in my createShareFile method:
Incorrect (original way):
return [NSURL URLWithString:[docFile stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
Correct way:
return [NSURL fileURLWithPath:docFile];
As soon as I fixed that, it started working, even with my custom file type.
I had a similar problem where the mail app was the only one I couldn't add a pdf to. Here is my code in Swift as well as handling iPad popup.
var filesToShare = [Any]()
filesToShare.append(self.myUrl)
let activityViewController = UIActivityViewController(activityItems: filesToShare as [Any], applicationActivities: nil)
present(activityViewController, animated: true)
// for iPad -> where to present on screen
if let popOver = activityViewController.popoverPresentationController {
//action button being my top left icon
popOver.barButtonItem = self.actionButton
}
My issue was as well handling the URL differently
Hi can anyone tell me how I can make the Share Sheet in iOS 6 black? I know how to make Action Sheets black. I use this code for Action Sheet:
[actionsheetshare setActionSheetStyle:(UIActionSheetStyleBlackTranslucent)];
[Eded]
so does it look by default
Here is my Code I use: NSString* someText = #"";
NSArray* dataToShare = #[someText]; // ...or whatever pieces of data you want to share.
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:#[someText]
applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:^{}];
You need to set UIStatusBarHidden to 'NO' in your Info.plist. If you have this property set to 'YES', the UIActivityViewController always appears with a grey tint.
I believe that this is a bug and I have filed it as such on Radar (problem #12682274).
What code you have written, i just had the below lines.. shows the black translucent, check by using this..
NSArray* arr = [[NSArray alloc] initWithObjects:[NSURL URLWithString:#"http://www.google.com"],#"Hello Guys", nil];
UIActivityViewController* activity = [[UIActivityViewController alloc] initWithActivityItems:arr applicationActivities:nil];
[self presentViewController:activity animated:YES completion:nil];
The whole view is simple UIView with an collection view, you can use its subviews like below to modify as you like
activity.view.subviews
Finally been making it through Apple's (rather dismal) documentation on the new UIActivityViewController class and the UIActivityItemSource protocol, and I'm trying to send different data sets to different actions called from the activity view. To simplify things, I'm looking at two things.
A Facebook posting action, which should say "Check this out!" and also attach a URL to the post (with that cute little paperclip).
A Twitter posting action, which should say "Check this out, with #hashtag!" and also attach that same URL (with the same paperclip).
Here's the code I've got implemented right now.
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType {
if ([activityType isEqualToString:UIActivityTypePostToFacebook]) {
return #"Check this out!";
} else if ([activityType isEqualToString:UIActivityTypePostToTwitter]) {
return #"Check this out, with #hashtag!";
}
return #"";
}
- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController {
return #"";
}
And then when I set up this activity view controller (it's in the same class), this is what I do.
UIActivityViewController *activityView = [[UIActivityViewController alloc] initWithActivityItems:#[self] applicationActivities:nil];
[self presentViewController:activityView animated:YES completion:nil];
My dilemma is how to attach that NSURL object. It's relatively easy when calling the iOS 6 SL-class posting modals; you just call the individual methods to attach a URL or an image. How would I go about doing this here?
I'll note that instead of returning NSString objects from -activityViewController:itemForActivityType, if I return just NSURL objects, they show up with that paperclip, with no body text in the post. If I return an array of those two items, nothing shows up at all.
Evidently it was as simple as this: passing in an array to the first argument of UIActivityViewController's init call, with each item in the array handling a different data type that will end up in the compose screen. self handles the text, and the second object (the NSURL) attaches the URL.
NSArray *items = #[self, [NSURL URLWithString:#"http://this-is-a-url.com"]];
UIActivityViewController *activityView = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
[self presentViewController:activityView animated:YES completion:nil];
Really wish there was more on this, but here it is.
, Hello, everyone.
I'm developing my app which has a feature to post article from website.
This is a picture of UIWebview with UIMenuController.
It was possible to get event when user tap the button. but I can't find the way to get the text the user selected.
In UITextView case, it has 'selectedRange' property, so it is easy to get selection text.
UIMenuItem *facebookMenuItem = [[UIMenuItem alloc] initWithTitle:#"Facebook" action:#selector(facebookMenuItemTapped:)];
UIMenuItem *twitterMenuItem = [[UIMenuItem alloc] initWithTitle:#"Twitter" action:#selector(twitterMenuItemTapped:)];
[UIMenuController sharedMenuController].menuItems = [NSArray arrayWithObjects: facebookMenuItem, twitterMenuItem, nil];
[twitterMenuItem release];
[facebookMenuItem release];
I would like to get the selection text on UIWebView.
Does anybody have an idea or hint?
Thanks.
Or if you donʾt want to mess with Javascript you can just copy the selection to the pasteboard and then retrieve it by running:
[[UIApplication sharedApplication] sendAction:#selector(copy:) to:nil from:self forEvent:nil];
NSString *text = [UIPasteboard generalPasteboard].string;
I am trying to change images of my tabbar in a ViewController, but to display the new images, I must click on each tab bar item.
for (CustomTabBarItem *myItem in self.tabBarController.tabBar.items){
myItem.enabled = YES;
myItem.badgeValue = #"1";
UIImage *myImage = [[UIImage alloc] initWithContentsOfFile:[[DesignManager sharedManager] getPathOfFile:#"test.png"]];
*myItem.imageSelect= *myImage; // change images of each item. don't appear if I dont click on the item
}
Anyone know How can I can display directly these images?
Thanks
You need to replace the old tab bar item with a new one. You can't update the image dynamically otherwise.
The easiest way to do this is to set the tabBarItem property of the view-controller represented by a given tab. If you wanted to do this from within that view controller, just write:
self.tabBarItem = [[UITabBarItem alloc] initWithTitle: #"title" image: myImage: tag: nil];
Or, you could do this from somewhere else, say your app delegate:
UIViewController* vc = [tabBarController.viewControllers objectAtIndex: 3];
vc.tabBarItem = [[UITabBarItem alloc] initWithTitle: #"title" image: myImage: tag: nil];
I know this is an old question. I ran into the same problem when I need to update the badge value from another active tab. Creating another UITabBarItem will solve your current problem but causes potential memory leak when this code is called many times. Plus, when other view controllers access the tab, they do not have reference to newly created UITabBarItem. My trick is
vc.tabBarItem = vc.tabBarItem;
It works for me.