Maybe you are running into the same issue. So, I considered to write this topic. All began when I was testing the new AirPrint iOS 4.2 feature with my existing applications. In my case, Implementing AirPrint feature into your application is pretty simple. You just instantiate the Airprint UIKit objects, based on Apple's sample [1] and you are all set. For instance, to print a webview content (that was my case), just add this method into your View Controller .m code and let iOS 4.2 do the rest for you, I mean, show you the window to choose number os copies, select printer etc:
- (void)printWebPage {
if ([UIPrintInteractionController class]) {
UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
if(!controller){
NSLog(@"Couldn't get shared UIPrintInteractionController!");
return;
}
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if(!completed && error){
NSLog(@"FAILED! due to error in domain %@ with error code %u",
error.domain, error.code);
}
};
if ([UIPrintInfo class]) {
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [Singleton sharedInstance].globalBlogTitle;
printInfo.duplex = UIPrintInfoDuplexLongEdge;
controller.printInfo = printInfo;
controller.showsPageRange = YES;
}
if ([UIViewPrintFormatter class]) {
UIViewPrintFormatter *viewFormatter = [self.blogDetailsWebView viewPrintFormatter];
viewFormatter.startPage = 0;
controller.printFormatter = viewFormatter;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[controller presentFromBarButtonItem:self.navigationItem.rightBarButtonItem animated:YES completionHandler:completionHandler];
} else
[controller presentAnimated:YES completionHandler:completionHandler];
}
}
}
Now, take a look at above code. I need to preview if user has an iOS version smaller than 4.2 and avoid crashes or bogus references in my application. iOS 4.1 and previous don't know what UIPrintInteractionController, UIViewPrintFormatter and UIPrintInfo mean. So, I need to test for these classes existence and instruct my code where to go in this case [2].
[Session started at 2010-12-12 08:53:27 -0200.]
dyld: Symbol not found: _OBJC_CLASS_$_UIPrintInfo
Referenced from: /Users/marcelo_palermo/Library/Application Support/iPhone Simulator/3.2/Applications/3ABCAD78-5788-4FFA-8F12-B5AD805E1AC5/MyApp.app/MyApp
Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/
SDKs/iPhoneSimulator3.2.sdk/System/Library/Frameworks/UIKit.framework/UIKit
in /Users/marcelo_palermo/Library/Application Support/iPhone Simulator/3.2/Applications/3ABCAD78-5788-4FFA-8F12-B5AD805E1AC5/MyApp.app/MyApp
- The base SDK for your Xcode project must be iOS 4.2 or newer. The name for this setting in the build settings editor is
SDKROOT (Base SDK)
. - The deployment target for your project must be iOS 3.1 or newer. The name for this setting is
MACOSX_DEPLOYMENT_TARGET (Mac OS X Deployment Target)
. - The compiler for your project must be the LLVM-GCC 4.2 compiler or newer, or the LLVM compiler (Clang) 1.5 or newer. The name for this setting is
GCC_VERSION (C/C++ Compiler Version)
. - You must ensure that any frameworks not available in your project’s deployment target are weakly linked, rather than required