After days of google and brilliant help from an user of this forum and studying the xcode 4.2 example photoprint, i managed to print much easier via a simple ibaction and a predefined local resource file, here is the code -
sdk 4.2, uikit framework included,demo.jpg is a local resource file could be also a pdf or doc file instead:
and think different and above all think simple!!!!
in .h:
#import <UIKit/UIKit.h>
@interface xyviewController : UIViewController <...,UIPrintInteractionControllerDelegate> {
UIPrintInteractionControllerDelegate should be delegate
}
-(IBAction)printdoc;
in .m:
Note: for testing on hardware device, be sure airport is enabled and logged to printing wifi network, if you use a shared usb printer on a mac - enable sharing (think of AirPrintHacktivator if you can't share your usb printer) real wifi printer work should work without problems.
If the no airprint printer is available in the wifi network printing popover will not be shown and if you are pressing the ibaction button nothing happens !!!
Here is my code for putting in Airprint into my iPad app. It is activated from an Actionsheet. It is grabbing the strings from two UITextViews and printing.
It seem that my code above, does not work under iOS 5.0 even if compiled for 4.x the uipopover for printing does not open under iOS 5.0 !!!
I'm working on it...
It seem that my code above, does not work under iOS 5.0 even if compiled for 4.x the uipopover for printing does not open under iOS 5.0 !!!
I'm working on it...
Does the Apple sample code for printing work on iOS 5? If there are compatibility issues I'm sure they update the sample to address the issue.
After days of google and brilliant help from an user of this forum and studying the xcode 4.2 example photoprint, i managed to print much easier via a simple ibaction and a predefined local resource file, here is the code -
sdk 4.2, uikit framework included,demo.jpg is a local resource file could be also a pdf or doc file instead:
and think different and above all think simple!!!!
in .h:
#import <UIKit/UIKit.h>
@interface xyviewController : UIViewController <...,UIPrintInteractionControllerDelegate> {
UIPrintInteractionControllerDelegate should be delegate
}
-(IBAction)printdoc;
in .m:
Note: for testing on hardware device, be sure airport is enabled and logged to printing wifi network, if you use a shared usb printer on a mac - enable sharing (think of AirPrintHacktivator if you can't share your usb printer) real wifi printer work should work without problems.
If the no airprint printer is available in the wifi network printing popover will not be shown and if you are pressing the ibaction button nothing happens !!!
hope it helps you
Tobias
Very cool! Would this work to print a local pdf file?
After some time of research (my neck hurts) i have found out the following:
My 30 lines KISS code does not work on iOS 5.x anymore even if it is compiled for iOS 4.0 on the iPad. It seems to work fine for iPhones iOS 5.0 but also not on universal apps.
The reason is simple but was hard to find, as there are not many tutorials for AirPrint and iOS 5.0, exactly zero ones...
Starting with iOS 5.0 you have to check on which device you are running your printing request ! This is actually done by:
When I click "Select Printer", it says "Looking for Printers..." for a few seconds and then says "No Printers Found". I'm running your iPad only version, and it works great until this part! Like you said, there's little to no tutorials online, so I was hoping you could give me some feedback! Thanks!
Just in case anyone else was stuck on that same issue, I found out that you have to download Airprint Activator on your computer in order to share the printer with iOS devices. You can find several tutorials online for it, and it should fix that problem of not being able to find these hidden printers. Thanks for the code though!
Just in case anyone else was stuck on that same issue, I found out that you have to download Airprint Activator on your computer in order to share the printer with iOS devices. You can find several tutorials online for it, and it should fix that problem of not being able to find these hidden printers. Thanks for the code though!
There's also Printopia, the one I use. It's commercial, and costs like 15 dollars. It's well worth it. It also lets you save to a folder on your Mac or to your DropBox, if you have one.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.