Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 17    Views: 447

MGoBlue
Apple Fan
Profile
Posts: 980
Reg: Jun 07, 2011
Gold River, CA
10,600
02/13/13 12:23 AM (12 years ago)

Updated Tutorial: Adding a Print Button to your iOS App

I've updated the tutorial I put together a while back. This fixes the issue where only the first pdf in a directory was printing. It's a simple addition of one more line of code. The updated tutorial is available on my website in html and a pdf download. http://jc-evans.com/blog/2013/02/12/new-tutorial-adding-a-print-button-to-an-app/
 
ianJamesPiano
Code is Art
Profile
Posts: 2661
Reg: Feb 13, 2011
Palm Springs, C...
37,010
like
02/13/13 12:36 AM (12 years ago)
Excellent!!
 
GraciousWolf_PE
Aspiring developer
Profile
Posts: 372
Reg: Feb 15, 2012
Montreal
10,720
like
02/13/13 12:36 AM (12 years ago)
Excellent update, @MGoBlue! Try this out if you want to remove some of the code and rid yourself of even having to include "shareTitle": Remove the following lines of code (or don't add them to begin with): NSString *shareTitle; @property (nonatomic, retain) NSString *shareTitle; @synthesize shareTitle; And alter the following line from: NSArray *components = [shareTitle componentsSeparatedByString:@"."]; To: NSArray *components = [self.localFileName componentsSeparatedByString:@"."]; It should bypass the need to add in the following line of code: shareTitle = self.localFileName Nonetheless, both methods work! Nicholas *EDIT* Just saw your message - indeed there are often many ways to get to the same function!
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
02/13/13 01:29 AM (12 years ago)
Awesome! Thanks for the update and good to see you back!
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
02/13/13 02:37 AM (12 years ago)
Very nice indeed! Thanks!! Cheers! -- Smug
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
02/13/13 06:41 AM (12 years ago)
Thanks @MGo, love this feature. Thinking about moving it to an action sheet......
 
MGoBlue
Apple Fan
Profile
Posts: 980
Reg: Jun 07, 2011
Gold River, CA
10,600
like
02/13/13 06:54 AM (12 years ago)
Nicholas - thanks. I think there was a reason I included shareTitle. It may have had to do with custom HTML pages. Your method is cleaner. Always good to have less code. Atrain - that sounds good,,,
 
tb
buzztouch Evangelist
Profile
Posts: 2050
Reg: Nov 03, 2011
Oxford
32,300
like
02/13/13 08:40 AM (12 years ago)
Fantastic! I look forward to implementing this into my app. I haven't seen you around the forums recently, but I'm glad to have you back.
 
feraco
Aspiring developer
Profile
Posts: 705
Reg: Jan 23, 2012
nyc
15,050
like
02/28/13 05:21 AM (12 years ago)
Hey I implemented this and it works great in the simulator but not on my device? any thoughts on why or how to get the print button workin gon my device?
 
mutzy
Aspiring developer
Profile
Posts: 841
Reg: Nov 03, 2010
Medford, MA
9,860
like
02/28/13 03:55 PM (12 years ago)
Anyone know how to do this with images instead? For example, substituting the "add" button for a printer icon?
 
Antonios
Apple Fan
Profile
Posts: 381
Reg: Feb 12, 2013
Korinthos, Gree...
4,610
like
03/29/13 09:40 AM (12 years ago)
Thank you you are the best...
 
bfoutty
Code is Art
Profile
Posts: 185
Reg: Jun 12, 2011
Youngstown, OH
12,650
like
04/28/13 09:14 AM (12 years ago)
@MGoBlue - this is hard for me to say as a Buckeye, but thanks for the code and the tutorials. Very useful. My students and their parents will find this feature quite useful. Go Bucks!! Beat Michigan!
 
sciurus
Lost but trying
Profile
Posts: 4
Reg: Oct 20, 2015
Cleveland
40
like
10/30/15 01:21 PM (9 years ago)
I've been following this tutorial, but when I get to the point where I need to edit the BT_viewUtilities section, the code referenced in the tutorial is not present in the file. Does this method still work?
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
10/31/15 02:40 AM (9 years ago)
The code referenced starts around line 347 of BT_viewController.m Cheers! -- Smug
 
sciurus
Lost but trying
Profile
Posts: 4
Reg: Oct 20, 2015
Cleveland
40
like
11/01/15 07:45 AM (9 years ago)
Ok, found it! Thank you. The tutorial says to look in "BT_viewUtilities" not "BT_viewController.m" Also, the code referenced is now different. The tutorial provides this: *** if([rightButtonType isEqualToString:@"home"]) theBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Print", @"Print") style:UIBarButtonItemStylePlain target:theViewController action:@selector(printdoc) ]; *** but the right button is now called "navBarRightButtonType" and when I add the "action:@selector(printdoc)" portion at the very end, I get a warning "Undeclared selector 'printdoc'" Not sure how to fix that last bit.
 
sciurus
Lost but trying
Profile
Posts: 4
Reg: Oct 20, 2015
Cleveland
40
like
11/02/15 10:22 AM (9 years ago)
I've been trying different things with this for the last day, but nothing seems to work. Nothing happens when I use the print button - I'm guessing it can't find the IBAction in order to trigger the print dialog. I've checked the code several times & copy/pasted it exactly from the tutorial with no luck. Does this method still work for others?
 
tb
buzztouch Evangelist
Profile
Posts: 2050
Reg: Nov 03, 2011
Oxford
32,300
like
11/02/15 01:32 PM (9 years ago)
I think the best solution might be to use the Share plugin, which includes the printing function in the 'share sheet'. https://www.buzztouch.com/plugins/plugin.php?pid=2C64C67C961948B1A03DBA0
 
sciurus
Lost but trying
Profile
Posts: 4
Reg: Oct 20, 2015
Cleveland
40
like
11/11/15 09:15 AM (9 years ago)
I've tried using the Share plugin now, but it is not detecting my Airprint printer. The Action Icon/Print function works fine in Safari, so I know this issue is specific to the app itself. I would still prefer a one-click print feature, instead of asking users to select their way through several screens using the Share Menu. If there are no further suggestions on getting this specific tutorial to work I'm probably going to scrap the project. I very much appreciate the feedback you all have given. Thanks.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.