4

I've implemented AirPrinting from my app but I'm facing a strange issue. Whenever the print dialog appears, there are no Cancel or Done/Print buttons displayed, as shown in the following image.

enter image description here

The code I'm using is as follows:

if ([UIPrintInteractionController canPrintURL:pdfUrl]) {  
        UIPrintInfo *aPrintInfo = [UIPrintInfo printInfo];  
        aPrintInfo.outputType = UIPrintInfoOutputGeneral;  
        aPrintInfo.jobName = [NSString stringWithFormat:@"%@-PRINT",[[NSUserDefaults standardUserDefaults] stringForKey:@"Kiosk ID"]];  
        UIPrintInteractionController *aPrintController = [UIPrintInteractionController sharedPrintController];  
        aPrintController.showsNumberOfCopies=YES;  
        aPrintController.showsPaperSelectionForLoadedPapers=YES;  
        aPrintController.printingItem = pdfUrl;  
        aPrintController.printInfo = aPrintInfo;  
        [aPrintController presentAnimated:YES completionHandler:NULL];  
}  

Does anyone have experience with this problem and know how to rectify? What's really odd is that the actions for these hidden buttons still work; so if I tap where the print button should be, it'll print and likewise I can close the dialog by tapping the top left where the Cancel button should be.

Cheers!

p.s using latest version of IOS 11, issue occurs in simulator and on device.

[Edit] I've just now tested a print example from Apple found at https://developer.apple.com/library/content/samplecode/PrintBanner/Introduction/Intro.html#//apple_ref/doc/uid/DTS40013422-Intro-DontLinkElementID_2

and although the code to bring up the AirPrint dialog are very similar (more-so after I tweaked a few bits of my code) the demo code worked as expected (buttons visible) while my code still does not. Very confusing.

[Edit 2] Using the code sample above in a fresh project works as expected too. Yet, in my full app, it does not. Does anyone have experience as to why that my be? Are system dialogs affected by the size of the app perhaps? Doesn't seem likely, but there is definitely something awry with my app using this code that isn't obvious.

[Edit 3] I enhanced the fresh project by incrementally introducing the same elements from my main project, going as far as bringing in the same Pods and setting up the same UI structure, and adding UIImage elements. It did not have the exact same number of views, and those were not doing the same things as my main project, but the memory usage was similar. And yet still, it worked. Are workspace corruptions a thing in Xcode, something behind the scenes not represented in any UI that might explain this?

[Edit 4] I just created a completely new project, reinstalled all the pods, then moved my source files from my original project to the new project. Quell surprise, the issue still remains in the new project.

[Edit 5] Solved! I finally found the issue thanks in part to the tip from the accepted answer below. It was due to having a global tint colour set to Clear, but also having individual Views within each controller also setting the tint colour to clear. This affected the dialog being shown and as such the buttons were invisible. Once I changed the Views to have an actual colour for the Tint property the print dialog buttons were once again visible.

Snouto
  • 1,039
  • 1
  • 7
  • 21
  • Does your code make use of UIAppearance? Does the view debugger show the buttons? – EricS Jan 11 '18 at 03:01
  • I don't have direct experience of UIAppearance but just quickly looking in to it, the UIPrintInteractionController class doesnt seem to have an appearance selector. Could this be due to it being a system dialog or were you thinking of something else? – Snouto Jan 11 '18 at 03:28
  • Are you able to tap the buttons even though they are not visible? – atulkhatri Jan 11 '18 at 08:55
  • Yes, I mentioned that in the OP – Snouto Jan 11 '18 at 08:59
  • 1
    I thought maybe you were using UIAppearance in part of your application that was affecting this view. – EricS Jan 11 '18 at 17:06
  • I agree with @EricS Comment seems like you are setting up some font color in your UIAppearance.What you can do it go into UIDebugger and check the buttons on the popup. Select the button you can see the properties, there you can find button font color. – Pallavi Srikhakollu Jan 12 '18 at 06:49
  • The code is as shown above, nowhere am I setting button colours for this dialog. That said I will look in to using the UIDebugger, perhaps it will reveal something useful. – Snouto Jan 12 '18 at 10:00
  • Unfortunately, and probably because the print dialog is a system dialog, the UIDebugger does not show anything to do with the print dialog so I can't see how that's being presented at all. – Snouto Jan 12 '18 at 10:08
  • Your comments did make me investigate another area of my project which _does_ adjust the colouring of a UIAlertController. I tried removing this code and rebuild, and even including it in to my test project, but in both cases the outcome was the same. UIPrintInteractionController inherits from NSObject rather than UIAlertController, so perhaps this is why the code has no effect on my issue... but it still makes me wonder if something is going on underneath. – Snouto Jan 15 '18 at 00:32

2 Answers2

1

I have also used your code and it is working as expected it has cancel and print button in iOS 11 also. Here is the code

([UIPrintInteractionController canPrintURL:self.pdfUrl]) {
        UIPrintInfo *aPrintInfo = [UIPrintInfo printInfo];
        aPrintInfo.outputType = UIPrintInfoOutputGeneral;
        aPrintInfo.jobName = @"test job";
        UIPrintInteractionController *aPrintController = [UIPrintInteractionController sharedPrintController];
        aPrintController.showsNumberOfCopies=YES;
        aPrintController.showsPaperSelectionForLoadedPapers=YES;
        aPrintController.printingItem = self.pdfUrl;
        aPrintController.printInfo = aPrintInfo;
        [aPrintController presentAnimated:YES completionHandler:NULL];
    }

Please check if pdfUrl is having valid URL, also in UI pdf should load if it is a valid url.

Below is the url which I am using

self.pdfUrl = [NSURL URLWithString:@"http://unec.edu.az/application/uploads/2014/12/pdf-sample.pdf"];

Edit 1:-

Attaching the screen shotenter image description here

Gyanendra
  • 361
  • 2
  • 15
  • Thank you for the reply but this doesnt solve anything for me. 1) my PDF certainly exists locally because a) I create it before printing and b) it prints just fine, and 2) I even tried your PDF link above and the outcome was the same: https://ibb.co/b8gcRm – Snouto Jan 11 '18 at 00:35
  • its really strange, because with the same url I am able to get the screen with cancel and print button. I will attach the scree shot for the same. – Gyanendra Jan 11 '18 at 05:52
  • May be you should try to convert it to NSData and try to print, if pdf is locally stored – Gyanendra Jan 11 '18 at 06:09
  • I think it's something more fundamental than that, perhaps even my workspace has become corrupt somewhere. I created a secondary project and incrementally introduced the same elements from my main project, going as far as bringing in the same Pods and setting up the same UI structure, and adding UIImage elements to get the memory usage to be similar. And yet still, it worked. I can't explain it. – Snouto Jan 11 '18 at 07:16
  • Please start using the new project :) – Gyanendra Jan 11 '18 at 09:47
1

There is no direct issue with UIPrintInteractionController code. As you mention click of done and cancel buttons are working as expected. The only problem is visibility of buttons.

Try changing navigation bar tint color before presenting print controller.

self.navigationBar.barStyle = UIBarStyle.Black
self.navigationBar.tintColor = .black

Note:- I don't have your code. This is only one of the problems and solution related to your issue.

Chanchal Warde
  • 983
  • 5
  • 17
  • Thanks for the reply but using `self.navigationController.navigationBar.barStyle=UIBarStyleBlack; self.navigationController.navigationBar.tintColor=UIColor.blackColor;` did not solve the problem. – Snouto Jan 16 '18 at 09:35
  • Hi snouto, I faced this issue in Image Picker controller. Are you using default navigation bar?? – Chanchal Warde Jan 16 '18 at 09:47
  • I have a navigation controller in my app but it's hidden, there is no nav bar shown. even so I tried your code and it didn't solve the issue for me. – Snouto Jan 16 '18 at 10:00
  • Did you debug in different os versions?? – Chanchal Warde Jan 16 '18 at 11:17
  • It's a system dialog so I can't debug it directly. But I'm always running the code to the same device and iOS version. – Snouto Jan 16 '18 at 23:31
  • Okay I finally found the issue, it was due to having a global tint colour set to Clear, but also having individual Views within each controller set the tint colour to clear. Once I changed all views to have an actual colour for the Tint property the print dialog buttons were once again visible, and much rejoicing was had. I'm happy to accept your answer as it was - essentially - correct. Thank you for your help! – Snouto Jan 17 '18 at 01:15
  • Glad it helped you :) – Chanchal Warde Jan 17 '18 at 05:44