Key note categories and examples for tech issues

App crashes when exporting as PDF on iPad

This is an example note

I took this note when I get a bug report on the user forum, which is about exporting as PDF on iPad.

Exception

Exception	NSException *	"UIPopoverPresentationController (<UIPopoverPresentationController: 0x1611467a0>) should have a non-nil sourceView or barButtonItem set before the presentation occurs."	0x0000600000e3d740

Solutions

It works!

diff --git a/ios/Inkdrop/PDFExporter.m b/ios/Inkdrop/PDFExporter.m
index 8a2047a..2115ae6 100644
--- a/ios/Inkdrop/PDFExporter.m
+++ b/ios/Inkdrop/PDFExporter.m
@@ -37,6 +37,11 @@ RCT_EXPORT_METHOD(exportAsPDF:(NSString* __nonnull)title
           UIActivityViewController* activityViewController = [[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil];
           if (activityViewController != nil) {
             AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
+            if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
+              CGRect screenRect = [[UIScreen mainScreen] bounds];
+              activityViewController.popoverPresentationController.sourceView = delegate.window.rootViewController.view;
+              activityViewController.popoverPresentationController.sourceRect = CGRectMake(screenRect.size.width / 2, screenRect.size.height, 10, 10);
+            }
             [delegate.window.rootViewController presentViewController:activityViewController animated:YES completion:^() {
             }];
           }
  • Commit: https://github.com/inkdropapp/xxxxxx/commit/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Get help

Got any questions about this page? Feel free to ask them on the user forum here.