2012-09-07 3 views
4

Im은 AirPrint를 사용하여 인쇄 할 수있는 기능을 찾고 있습니다.이미지를 AirPrint에 전송하는 기능

단추를 누를 때 myPic.jpg가 기본 AirPrint 장치에 인쇄되어야하는 btnPrint 단추가 있습니다. 그러나 나는 그런 기능이 있는지조차 알 수 없다.

xcode에서 AirPrint에 대한 많은 문서를 찾을 수 없습니다.

+3

이 질문은 엑스 코드 관련이 없습니다. –

답변

4

애플은 아마도 당신에게 도움이 될 documentation on printing을 가지고 있습니다.

그리고 다음은 Objective-C code for AirPrint에서입니다 :

확인 거세한 숫양 인쇄로 볼 수 있습니다 :

if ([UIPrintInteractionController isPrintingAvailable]) 
{ 
    // Available 
} else { 
    // Not Available 
} 

인쇄 버튼 클릭 후 :

-(IBAction) buttonClicked: (id) sender; 
{ 
    NSMutableString *printBody = [NSMutableString stringWithFormat:@"%@, %@",self.encoded.text, self.decoded.text]; 
    [printBody appendFormat:@"\n\n\n\nPrinted From *myapp*"]; 

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

    UIPrintInfo *printInfo = [UIPrintInfo printInfo]; 
    printInfo.outputType = UIPrintInfoOutputGeneral; 
    printInfo.jobName = self.titleLabel.text; 
    pic.printInfo = printInfo; 

    UISimpleTextPrintFormatter *textFormatter = [[UISimpleTextPrintFormatter alloc] initWithText:printBody]; 
    textFormatter.startPage = 0; 
    textFormatter.contentInsets = UIEdgeInsetsMake(72.0, 72.0, 72.0, 72.0); // 1 inch margins 
    textFormatter.maximumContentWidth = 6 * 72.0; 
    pic.printFormatter = textFormatter; 
    [textFormatter release]; 
    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 presentFromBarButtonItem:self.rightButton animated:YES completionHandler:completionHandler]; 

} 
+0

안녕하세요, 저는 같은 것을 구현하고 있습니다. 하지만 인쇄가 완료되었음을 알 수있는 방법이 있는지 알고 싶습니다. 대리자 메서드가 있습니까? –

관련 문제