Thanks to a kind stackoverflow member I now have AirPrint(ing) working perfectly from the iPhone, but the function call for the iPad is giving me fits. Here is what I have:
if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
pic.presentFromRect(self.view.frame, inView:self.view, animated:true, completionHandler: nil)
} else {
pic.presentAnimated(true, completionHandler: nil)
}
The line that calls the print dialog for the iPad is my Swift conversion of Objective-C code that I found numerous times through my Google searching on the topic. It runs and gets called correctly, but all it does is appear to "dim" the iPad screen on the simulator (like something is opening, but it's just a huge grey transparent rectangle that covers the entire screen). If I click anywhere on the dimmed screen it returns to normal and the program continues as if I never pressed my "Print" button (I am using my own "Print" button I created in the Storyboard). I can only test this on the simulator currently, so it could even be a beta bug for all I know... but I'm guessing I'm doing something wrong.
Any suggestions are appreciated!
Thanks.
Thanks to Aaron, my printer select pop-up for the iPad now works on every button in my program except the print button! :) Here is the relevant code:
@IBOutlet var myButton1: BorderedButton!
@IBOutlet var myButton2: BorderedButton!
@IBOutlet var myButton3: BorderedButton!
Works perfectly on all but button 3, which of course is my "Print" button. Here is the function for button 3:
@IBAction func button3Tapped() {
var pic:UIPrintInteractionController = .sharedPrintController()
var viewpf:UIViewPrintFormatter = myTextView.viewPrintFormatter()
pic.delegate = self
pic.showsPageRange = true
pic.printFormatter = viewpf
if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
pic.presentFromRect(self.myButton3.frame, inView:self.view, animated:true, completionHandler: nil)
} else {
pic.presentAnimated(true, completionHandler: nil)
}
}
Change that "self.myButton3.frame" to myButton1 or myButton2 and I get the printer select pop-up in the iPad simulator with no problems. But making it myButton3 just gives me the error "fatal error: unexpectedly found nil while unwrapping an Optional value". I'm willing to let it appear on one of the other buttons if I have no other choice, but it would probably be good for me to understand what in the heck is happening!
Thanks again!