gpt4 book ai didi

ios/iphone - [NSNull dataUsingEncoding :]: unrecognized selector sent to instance

转载 作者:行者123 更新时间:2023-11-29 10:45:32 25 4
gpt4 key购买 nike

谁能帮我说说错误是什么原因?

[NSNull dataUsingEncoding:]: unrecognized selector sent to instance

我被困在 iOS 应用程序的打印机插件上。

一段时间以来,我一直在努力让这个应用程序正常工作......观察到的代码可能有助于找到错误......

导入“APPPrinter.h”

@interface APPPrinter (Private)

- (UIPrintInteractionController*) getPrintController;

- (UIPrintInteractionController*) adjustSettingsForPrintController:(UIPrintInteractionController*)controller;

- (void) loadContent:(NSString*)content intoPrintController:(UIPrintInteractionController*)controller;

- (void) informAboutResult:(int)code callbackId:(NSString*)callbackId;

- (BOOL) isPrintServiceAvailable;

@end


@implementation APPPrinter

// Is printing available.

- (void) isServiceAvailable:(CDVInvokedUrlCommand*)command
{
CDVPluginResult* pluginResult;

pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsBool:[self isPrintServiceAvailable]];

[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];

- (void) print:(CDVInvokedUrlCommand*)command
{
if (![self isPrintServiceAvailable])
{
return;
}

NSArray* arguments = [command arguments];
NSString* content = [arguments objectAtIndex:0];

UIPrintInteractionController* controller = [self getPrintController];

[self adjustSettingsForPrintController:controller];
[self loadContent:content intoPrintController:controller];

[self openPrintController:controller];

[self commandDelegate];

- (UIPrintInteractionController*) getPrintController
{
return [UIPrintInteractionController sharedPrintController];

- (UIPrintInteractionController*) adjustSettingsForPrintController:(UIPrintInteractionController*)controller
{
UIPrintInfo* printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
controller.printInfo = printInfo;
controller.showsPageRange = YES;

return controller;

- (void) loadContent:(NSString*)content intoPrintController:(UIPrintInteractionController*)controller
{
// Set the base URL to be the www directory.
NSURL *basEURL = [[NSBundle mainBundle] URLForResource:@"Login" withExtension:@"html"];

// Load page into a webview and use its formatter to print the page
UIWebView* webPage = [[UIWebView alloc] init];

[webPage loadHTMLString:content baseURL:basEURL];


UIViewPrintFormatter* formatter = [webPage viewPrintFormatter];

controller.printFormatter = formatter;
controller.showsPageRange = YES;
}
- (void) openPrintController:(UIPrintInteractionController*)controller
{
[self.commandDelegate runInBackground:^
{
[controller presentAnimated:YES completionHandler:NULL];

}];

[self performSelectorOnMainThread:@selector(openPrintController:) withObject:nil waitUntilDone:NO];
}

- (BOOL) isPrintServiceAvailable
{
Class printController = NSClassFromString(@"UIPrintInteractionController");

if (printController)
{
UIPrintInteractionController* controller = [UIPrintInteractionController sharedPrintController];

return (controller != nil) && [UIPrintInteractionController isPrintingAvailable];
}

return NO;
}

@end

任何关于创建和获取打印插件以在我的应用程序中运行的帮助/链接也将非常有用。

最佳答案

这意味着消息“dataUsingEncoding:”被发送到 NSNull 的一个实例。

在您的程序中的某处有一个对象,您显然认为它是一个 NSString*,但实际上它是一个 NSNull*。 NSNull 对象在数组和字典中用作占位符以表示“没有值”,因为您不能将 nil 存储在数组和字典中。

在Xcode中,点击“Breakpoints”,点击“+”,添加一个“Exception breakpoint”。再次运行你的程序。这次它将在调试器中恰好在尝试调用 dataUsingEncoding 的代码处停止:找出对象的来源并修复它。

关于ios/iphone - [NSNull dataUsingEncoding :]: unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22553944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com