Post

Replies

Boosts

Views

Activity

Reply to UIPrintInteractionController.shared on Mac OS Sonoma running iPad App
It turns out that our solution is not really a solution. It works with a single image, but not always. If we print multiple images on one page or on multiple pages, it doesn't work on the Mac. It doesn't matter whether we convert the images to JPG beforehand or not. It seems to be a timing problem. If we don't do anything in drawPageAtIndex, the print preview always appears. If we do a lot in drawPageAtIndex, the print preview doesn't appear on the Mac. It worked in earlier macOS versions. It always works on the iPhone and iPad. Unfortunately, we haven't been able to find a solution. It would be ideal if we had the option to only draw something in drawPageAtIndex when the print preview is already displayed. We have the instance method printInteractionControllerDidPresentPrinterOptions. This is called a moment before the print preview has actually been displayed. But we could set a flag from this method with a delay of perhaps one second so that something should only be drawn in drawPageAtIndex from then on. However, we are missing the option to restart the drawing in the print preview using the programming code. If, for example, the print orientation is changed manually in the print preview dialog, then drawPageAtIndex is called again and everything is drawn correctly. Does anyone know a way to restart the drawing in drawPageAtIndex of the UIPrintPageRenderer from the programming code?
Jun ’24
Reply to UIPrintInteractionController.shared on Mac OS Sonoma running iPad App
And an html string can be printed using a UIGraphicsBeginPDFContextToData. The disadvantage is that you have to define a fixed page size, but it prints with this solution in an iPad app on the Mac. - (NSData *)createPDFfromHTML:(NSString *)htmlString { UIMarkupTextPrintFormatter *formatter = [[UIMarkupTextPrintFormatter alloc] initWithMarkupText:htmlString]; UIPrintPageRenderer *pageRenderer = [[UIPrintPageRenderer alloc] init]; [pageRenderer addPrintFormatter:formatter startingAtPageAtIndex:0]; NSMutableData *pdfData = [NSMutableData data]; CGRect paperRect = CGRectMake(0, 0, 595.3, 841.9); // A4 CGRect printableRect = CGRectInset(paperRect, 72, 72); // 1-inch margins UIGraphicsBeginPDFContextToData(pdfData, paperRect, nil); [pageRenderer setValue:[NSValue valueWithCGRect:paperRect] forKey:@"paperRect"]; [pageRenderer setValue:[NSValue valueWithCGRect:printableRect] forKey:@"printableRect"]; NSInteger pages = [pageRenderer numberOfPages]; for (NSInteger i = 0; i < pages; i++) { UIGraphicsBeginPDFPageWithInfo(paperRect, nil); [pageRenderer drawPageAtIndex:i inRect:paperRect]; } UIGraphicsEndPDFContext(); return pdfData; } - (void)printHtmlTest { NSString *htmlContent = @"<h1>Hello World</h1>"; NSData * pdfData = [self createPDFfromHTML:htmlContent]; UIPrintInteractionController *printController = [UIPrintInteractionController sharedPrintController]; printController.printingItem = pdfData; UIViewController *controller = [[UIViewController alloc] init]; [printController presentAnimated:YES completionHandler:^(UIPrintInteractionController *printInteractionController, BOOL completed, NSError *error) { // }]; }
May ’24
Reply to UIPrintInteractionController.shared on Mac OS Sonoma running iPad App
We have finally found a solution for this problem. Where it works, we load the UIImage from a JPG file. Where it doesn't work, the UIImage is created programmatically. The solution is to convert the UIImage to JPEG data and then create a new UIImage for printing. With this new UIImage, printing finally also works on a Mac in an iPad app. UIImage *imageToPrint = [UIImage imageWithData:UIImageJPEGRepresentation(originalImage, 1)];
May ’24
Reply to UIPrintInteractionController.shared on Mac OS Sonoma running iPad App
We have now noticed an interesting behavior in one of our apps. The app uses the same code to print from two different UIViewControllers. On a Mac as an iPad app it works without any problems in one of the two ViewControllers. The print preview appears and you can print. But in the other ViewController it doesn't work. The print preview does not appear. Unfortunately we cannot find the difference that causes the different behavior. The ViewController in which it works is called with push segue from the first controller. We thought that maybe that was the important difference. But in another app of ours we have exactly the same configuration and printing in the second ViewController doesn't work in this app.
May ’24
Reply to UIPrintInteractionController.shared on Mac OS Sonoma running iPad App
The new macOS version Sonoma 14.4 has just been released. Unfortunately the bug is still not fixed. It is still not possible to print with a "Designed for iPad" app. However, more errors are now displayed in the console: CLIENT ERROR: TUINSRemoteViewController does not override -viewServiceDidTerminateWithError: and thus cannot react to catastrophic errors beyond logging them Failed to connect (genericPrinterImage) outlet from (PMPrinterSelectionController) to (NSImageView): missing setter or instance variable Failed to connect (localPrintersLabel) outlet from (PMPrinterSelectionController) to (NSTextField): missing setter or instance variable Failed to connect (otherPrintersLabel) outlet from (PMPrinterSelectionController) to (NSTextField): missing setter or instance variable Failed to connect (recentPrintersLabel) outlet from (PMPrinterSelectionController) to (NSTextField): missing setter or instance variable CGContextClipToRect: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Mar ’24
Reply to Crash When Run app On Xcode15 Simulator
We migrated all UIGraphicsBeginImageContext code in all our apps to UIGraphicsImageRenderer and the crashes disappeared. Now everything is good again. UIGraphicsImageRendererFormat *format = [UIGraphicsImageRendererFormat defaultFormat]; format.opaque = NO; format.scale = 1; format.preferredRange = UIGraphicsImageRendererFormatRangeStandard; UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:imageSize format:format]; UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) { CGContextRef context = rendererContext.CGContext; }];
Feb ’24
Reply to Why does App Store Connect mess up the order of uploaded screenshots?
So now the automatic sorting of the screenshots is also broken. It has worked perfectly for at least 10 years and now it is sorted by upload order. The screenshots with the smallest file size are uploaded first and are placed at the front. This makes it random and unusable. Three months ago it worked perfectly. Now I have to upload each image one after the other for 33 languages, 4 device types and 10 screenshots each, i.e. a total of 1320 screenshots. That's another way to waste your valuable time.
Jan ’24
Reply to Crash When Run app On Xcode15 Simulator
We are also seeing crashes with UIGraphicsBeginImageContext on iOS 17 devices. At first we also thought that it would happen because of a 0 in the width or height of the size. But it crashes in one app at this point: if(size.width < 50 || size.height < 50) { return nil; } size = CGSizeMake(size.width*2.0f, size.height*2.0f); UIGraphicsBeginImageContext(size); With this code, it is impossible for the width or height to be 0. The crash must therefore also have other causes. Unfortunately, we cannot reproduce the crash with our test devices. Incident Identifier: AAAAAAAAAA-893D-4C7B-A933-AAAAAAAAAA Hardware Model: iPad13,16 Process: AAAAAAAAAA [37228] Path: /private/var/containers/Bundle/Application/AAAAAAAAAA-F8FB-405B-8DC7-AAAAAAAAAA/AAAAAAAAAA.app/AAAAAAAAAA Identifier: AAAAAAAAAA.AAAAAAAAAA.AAAAAAAAAA Version: 13.6 (1.0) AppStoreTools: 15A240a AppVariant: 1:iPad13,16:15 Code Type: ARM-64 (Native) Role: Background Parent Process: launchd [1] Coalition: AAAAAAAAAA.AAAAAAAAAA.AAAAAAAAAA [700] Date/Time: 2023-11-24 21:03:57.5000 -0500 Launch Time: 2023-11-24 08:47:34.0066 -0500 OS Version: iPhone OS 17.1.1 (21B91) Release Type: User Report Version: 104 Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Termination Reason: SIGNAL 6 Abort trap: 6 Terminating Process: AAAAAAAAAA [37228] Triggered by Thread: 0 Last Exception Backtrace: 0 CoreFoundation 0x18863c870 __exceptionPreprocess + 164 (NSException.m:249) 1 libobjc.A.dylib 0x1809a7c00 objc_exception_throw + 60 (objc-exception.mm:356) 2 Foundation 0x187ba6e54 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 172 (NSException.m:261) 3 UIKitCore 0x18a8683a4 _UIGraphicsBeginImageContextWithOptions + 568 (UIGraphics.m:407) 4 AAAAAAAAAA 0x100a9e83c -[AAAAAAAAAA getAaaaaImage:] + 88 (AAAAAAAAAA.m:7815) 5 AAAAAAAAAA 0x100a9e6b0 -[AAAAAAAAAA createAaaaa] + 92 (AAAAAAAAAA.m:7783) 6 AAAAAAAAAA 0x100a8b14c -[AAAAAAAAAA setAaaaaSize:] + 2664 (AAAAAAAAAA.m:2566) 7 AAAAAAAAAA 0x100a84164 -[AAAAAAAAAA viewDidLayoutSubviews] + 284 (AAAAAAAAAA.m:890) 8 UIKitCore 0x18a7a67f0 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1876 (UIView.m:20001) 9 QuartzCore 0x189bbc1c0 CA::Layer::layout_if_needed(CA::Transaction*) + 500 (CALayer.mm:10804) 10 UIKitCore 0x18a7a9744 -[UIView(Hierarchy) layoutBelowIfNeeded] + 296 (UIView.m:14119) 11 UIKitCore 0x18a7ac3e8 -[UINavigationController _layoutViewController:] + 816 (UINavigationController.m:7728) 12 UIKitCore 0x18a7ac0b4 -[UINavigationController _layoutTopViewControllerLookForNested:] + 436 (UINavigationController.m:5626) 13 UIKitCore 0x18a9392a0 __105-[UINavigationController _repositionPaletteWithNavigationBarHidden:duration:shouldUpdateNavigationItems:]_block_invoke + 440 (UINavigationController.m:3149)
Nov ’23
Reply to UIDocumentPickerViewController ignores directoryURL on iOS/iPadOS 16.1
Ok, now I understood how directoryURL from the UIDocumentPickerViewController works. It expects a security-scoped URL. Either a direct "Security Scoped URL" or from a "Security-Scoped Bookmark". This means that the user must first select the folders that are to be available using the UIDocumentPickerViewController with directoryURL. The returned security-scoped URLs can be saved as security-scoped bookmarks and later one can be passed to the UIDocumentPickerViewController as directoryURL.
Nov ’23
Reply to UIDocumentPickerViewController ignores directoryURL on iOS/iPadOS 16.1
In the method "documentPicker:didPickDocumentsAtURLs:" I get the path in this form: "/private/var/mobile/Containers/Shared/AppGroup/529E1B6C-A2B3-47E3-3623-7D5AC5F11BBC/File Provider Storage/Downloads/" I try to assign this path as a directoryURL when calling a UIDocumentPickerViewController again. That does not work. The UIDocumentPickerViewController opens the last used path and not "Downloads". Maybe I have to change the path somehow to make it work? No longer “Shared/AppGroup/” but direct path to the “Files” app. But how do I have to change the path?
Nov ’23