Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
自动航空打印IOS_Ios_Objective C_Printing_Airprint - Fatal编程技术网

自动航空打印IOS

自动航空打印IOS,ios,objective-c,printing,airprint,Ios,Objective C,Printing,Airprint,我需要在没有用户交互的情况下在Xcode中在后台进行AirPrint。我不在乎是否必须使用第三方框架来实现这一点。这是我的代码,但需要用户的交互 NSMutableString *printBody = [NSMutableString stringWithFormat:@"%@",TextField.text]; UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintControll

我需要在没有用户交互的情况下在Xcode中在后台进行AirPrint。我不在乎是否必须使用第三方框架来实现这一点。这是我的代码,但需要用户的交互

 NSMutableString *printBody = [NSMutableString stringWithFormat:@"%@",TextField.text];

    UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
    pic.delegate = self;


    UIPrintInfo *printInfo = [UIPrintInfo printInfo];
    printInfo.outputType = UIPrintInfoOutputGeneral;
    printInfo.jobName = @"PrintJob";
    pic.printInfo = printInfo;


    UISimpleTextPrintFormatter *textFormatter = [[UISimpleTextPrintFormatter alloc] initWithText:printBody];
    textFormatter.startPage = 0;
    textFormatter.contentInsets = UIEdgeInsetsMake(72.0, 72.0, 72.0, 72.0);
    textFormatter.maximumContentWidth = 6 * 72.0;
    pic.printFormatter = textFormatter;
    pic.showsPageRange = YES;


void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
    if (!completed && error) {
        NSLog(@"Printing could not complete because of error: %@", error);
    }
};


    [pic presentAnimated:YES completionHandler:completionHandler];
如果有人能帮忙,那就太好了

!这是iOS 8的wwdc视频,他们刚刚引入了一种新的打印方式,无需使用UIPrintInteractionController。给你

    -(IBAction)print:(id)sender{

      NSMutableString *printBody = [NSMutableString stringWithFormat:@"Hey this is a test lets hope it works!"];

      UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
      pic.delegate = self;


      UIPrintInfo *printInfo = [UIPrintInfo printInfo];
      printInfo.outputType = UIPrintInfoOutputGeneral;
      printInfo.jobName = @"PrintJob";
      pic.printInfo = printInfo;


      UISimpleTextPrintFormatter *textFormatter = [[UISimpleTextPrintFormatter alloc] initWithText:printBody];
      textFormatter.startPage = 0;
      textFormatter.contentInsets = UIEdgeInsetsMake(72.0, 72.0, 72.0, 72.0);
      textFormatter.maximumContentWidth = 6 * 72.0;
      pic.printFormatter = textFormatter;
      pic.showsPageRange = YES;
//save your printer using code also in video. 

      UIPrinter *SavedPrinterUserDefaults = [[NSUserDefaults standardUserDefaults]
                                             objectForKey:@"SavedPrinter"];
      [pic printToPrinter:SavedPrinterUserDefaults
        completionHandler:^(UIPrintInteractionController *printInteractionController, BOOL completed, NSError *error) {
          if (completed && !error)
            NSLog(@"YAYA! it printed");
        }];

    }

我希望这能帮助任何有同样问题的人

你想不做任何动作就自动打印吗?你看了吗?::是的@DarjiJigar这就是我想要的do@Connor您是否在viewdidload方法中尝试过此代码