iOS打印 AirPrint

使用iOS AirPrint 讓你的APP輕松實現(xiàn)打印功能

1, 什么是AirPrint

其實就是將iOS(iphone,ipad)上的內(nèi)容,使用支持AirPrint的打印機打印出來。打印過程無線控制, 非常方便。

2, 第一手資料

學(xué)習(xí)iOS, 第一手資料肯定非蘋果官方文檔莫屬.here。 (我下面敘述的內(nèi)容基本上是對文檔的總結(jié), 英語可以的建議直接看文檔。。。)

3, Printer Simulator,使用打印模擬器進行測試

既然涉及打印功能,那么就需要有一臺支持AirPrint 功能的打印機進行測試嘍,你沒有?沒關(guān)系!蘋果已經(jīng)為我們準備好了模擬器。 這個模擬器在Xcode中沒有, 需要自己到官網(wǎng)下載:下載Printer Simulator(需要先注冊登錄)



點擊Printer Simulator即打開模擬打印機


4、打印代碼

協(xié)議UIPrintInteractionControllerDelegate

主要是用到了UIPrintInteractionController類,這是一個單列類。UIPrintInfo是配置打印信息,UISimpleTextPrintFormatter是設(shè)置頁面范圍。

UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];

? ? ? ? ? ? ? ? if? (pic && [UIPrintInteractionControllercanPrintData:data]) {

? ? ? ? ? ? ? ? ? ? pic.delegate=self;

? ? ? ? ? ? ? ? ? ? UIPrintInfo*printInfo = [UIPrintInfoprintInfo];

? ? ? ? ? ? ? ? ? ? printInfo.outputType=UIPrintInfoOutputGeneral;

//? ? ? ? ? ? ? ? ? ? printInfo.jobName = [self.path lastPathComponent];

? ? ? ? ? ? ? ? ? ? printInfo.duplex=UIPrintInfoDuplexLongEdge;

? ? ? ? ? ? ? ? ? ? pic.printInfo= printInfo;

? ? ? ? ? ? ? ? ? ? pic.showsPageRange=YES;

? ? ? ? ? ? ? ? ? ? pic.printingItem= data;


? ? ? ? ? ? ? ? ? ? void(^completionHandler)(UIPrintInteractionController*,BOOL,NSError*) =

? ? ? ? ? ? ? ? ? ? ^(UIPrintInteractionController*pic,BOOLcompleted,NSError*error) {

? ? ? ? ? ? ? ? ? ? ? ? if(!completed && error)

? ? ? ? ? ? ? ? ? ? ? ? ? ? NSLog(@"FAILED! due to error in domain %@ with error code %u",

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? error.domain, error.code);

? ? ? ? ? ? ? ? ? ? };

? ? ? ? ? ? ? ? ? ? if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {

? ? ? ? ? ? ? ? ? ? ? ? [picpresentFromBarButtonItem:self.saveButtonanimated:YES

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? completionHandler:completionHandler];

? ? ? ? ? ? ? ? ? ? }else{

? ? ? ? ? ? ? ? ? ? ? ? [picpresentAnimated:YEScompletionHandler:completionHandler];

? ? ? ? ? ? ? ? ? ? }

Info.plist文件中的第一項 Localization native development region(CFBundleDevelopmentRegion)的值設(shè)為 China(zh_CN);



選擇后打印會生成一張圖片模擬結(jié)束
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 使用iOS AirPrint 讓你的APP輕松實現(xiàn)打印功能 2016/05/13 · iOS開發(fā) · 打印分享到:...
    蕭城x閱讀 6,924評論 2 10
  • 無線打印打印流程 a.創(chuàng)建 UIPrintInteractionController 實例。 b.創(chuàng)建UIPrin...
    huaiOS閱讀 2,118評論 0 1
  • 本文轉(zhuǎn)載xianghuibeijingCSDN 轉(zhuǎn)載過程中部分內(nèi)可能丟失!請參考原作者:http://blog....
    大熊Q閱讀 3,275評論 0 12
  • 我們需要進度條,我們需要“剩余時間”。 想到之前火過的一個知乎問題:“為什么有些男生追到一半就不追了”,底下有一個...
    Kernholz閱讀 201評論 0 0
  • 歲月如梭,匆匆而過。逝去的歲月,我們還能找回來嗎?人生就像是一條單行線,有去無回。如果今天我們注重保養(yǎng),...
    健康顧問一小欣閱讀 4,985評論 0 0

友情鏈接更多精彩內(nèi)容