iOS端PDFTron移除ThumbnailViewController编辑按钮及架构适配问题咨询
1. Removing Edit/Delete Buttons in ThumbnailViewController
Since you can't modify the source ThumbnailsViewController.m directly in the dynamic framework, you have two reliable workarounds using Objective-C runtime or view inspection:
Option 1: Method Swizzling to Override Setup
You can use method swizzling to intercept the view setup of theThumbnailsViewControllerand remove/hide the edit button. Here's a practical implementation:#import <objc/runtime.h> #import <PDFNet/PDFNet.h> @implementation ThumbnailViewControllerSwizzler + (void)load { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ Class targetClass = NSClassFromString(@"ThumbnailsViewController"); SEL originalSel = @selector(viewDidLoad); SEL swizzledSel = @selector(swizzled_viewDidLoad); Method originalMethod = class_getInstanceMethod(targetClass, originalSel); Method swizzledMethod = class_getInstanceMethod([self class], swizzledSel); BOOL didAddMethod = class_addMethod(targetClass, originalSel, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod)); if (didAddMethod) { class_replaceMethod(targetClass, swizzledSel, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)); } else { method_exchangeImplementations(originalMethod, swizzledMethod); } }); } - (void)swizzled_viewDidLoad { [self swizzled_viewDidLoad]; // Execute original setup logic // Filter out the edit/delete button from navigation bar NSMutableArray *filteredBarItems = [NSMutableArray array]; for (UIBarButtonItem *item in self.navigationItem.rightBarButtonItems) { if (![item.title isEqualToString:@"Edit"] && item.action != @selector(toggleEditing:)) { [filteredBarItems addObject:item]; } } self.navigationItem.rightBarButtonItems = filteredBarItems; } @endAdd this category to your project — it will automatically modify the
ThumbnailsViewController's navigation bar when it loads.Option 2: Observe View Appearance to Modify Buttons
If swizzling feels too invasive, you can listen for when the thumbnail view controller appears, then adjust its navigation items:// Add this in your app delegate or parent view controller [[NSNotificationCenter defaultCenter] addObserverForName:UIViewControllerDidAppearNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) { UIViewController *vc = note.object; if ([vc.class.description isEqualToString:@"ThumbnailsViewController"]) { NSMutableArray *cleanedItems = [NSMutableArray array]; for (UIBarButtonItem *item in vc.navigationItem.rightBarButtonItems) { if (![item.title isEqualToString:@"Edit"]) { [cleanedItems addObject:item]; } } vc.navigationItem.rightBarButtonItems = cleanedItems; } }];
2. Fixing "no matching architecture in universal wrapper" Error for Tools.framework
This error occurs because your custom-built Tools.framework lacks the arm64 architecture required for physical iOS devices (simulators use x86_64/arm64 simulator architectures). Follow these steps to fix it:
Step 1: Verify Framework Architectures
Open Terminal, navigate to your framework's directory, and run:lipo -info Tools.framework/ToolsIf
arm64isn't listed, that's the root cause.Step 2: Recompile for All Required Architectures
When building the PDFTron Tools framework in Xcode:- Select the
Toolstarget, go to Build Settings > Architectures. - Set Valid Architectures to include
arm64,armv7(if supporting older devices). - Set Build Active Architecture Only to
NOfor both Debug and Release configurations. - Build separately for Simulator and Physical Device, then merge the binaries with:
lipo -create /path/to/simulator/Tools.framework/Tools /path/to/device/Tools.framework/Tools -output /path/to/universal/Tools.framework/Tools
- Select the
Step 3: Adjust App Project Settings
In your app's Build Settings:- Set Excluded Architectures to
i386andx86_64for the Release (Universal Device) configuration. - Ensure Always Embed Swift Standard Libraries is set to
YES(if the framework uses Swift).
- Set Excluded Architectures to
Step 4: Clean and Rebuild
Clean your project (Cmd+Shift+K), delete derived data, then rebuild the app for the universal device target.
内容的提问来源于stack exchange,提问作者Nikhil Gupta

