iOS启用AirPrint的uiwebview内容 [英] iOS enabling AirPrint for uiwebview contents

查看:96
本文介绍了iOS启用AirPrint的uiwebview内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是XCode和App开发的超级新手。我目前正在iPad的uiwebviews中加载基于Web的应用程序。加载一个特定页面后,它将显示一个pdf文件。 我希望能够使用AirPrint打印此pdf文件。我正在寻找一个简单的解决方案。目前,我正在使用的应用有6个文件。

I am super new to XCode and App development. I currently am loading up a web based application in uiwebviews on the iPad. When one particular page is loaded, it displays a pdf file. I would like to be able to print this pdf file using AirPrint. I am looking for a simple solution. Currently the app I am working on has 6 files which it uses.

-ViewController.m
-ViewController.h
-MainStoryboard_iPad.storyboard
-MainStoryboard_iPhone.storyboard
-AppDelegate.h
-AppDelegate.m

在MainStoryboard文件中,有许多窗口(图形)对中央导航系统都很喜欢。如果可以花一些时间来真正地解释我需要做的事情,而不是看看这个链接。我有编程经验,但是从未使用过XCode或与Apple相关的任何产品。

In the MainStoryboard files, there are many windows (graphical) which are liked to a central navigation system. If it is possible to spend some time to really explain what I need to do, and not 'take a look at this link.' I have programming experience, but never with XCode or any product related to Apple.

推荐答案

我知道了如何做到这一点。首先,我在这里找到了一段代码, iOS Air print for UIwebview ,我没有当时想知道如何实现它,但是随后我做了如下操作。

I figured out how to do this. Firstly I found a piece of code here, iOS Air print for UIwebview, I had no idea how to implement this at the time, but then I did as follows.

我的应用程序是一个单视图XCode项目

在我的情节提要中,我插入了一个按钮(在导航栏上),并将其标识符更改为 Action,然后确保打开 tuxedo编辑器视图,并显示我的ViewController。 m文件,我在按住控件的同时单击并从按钮拖到ViewController.m文件。这在询问我的按钮ID后插入了我的IBAction方法。

In my storyboard I inserted a button (on my navigation bar) and changed its Identifier to 'Action' then, making sure to have the 'tuxedo' editor view open, displaying my ViewController.m file, I clicked and dragged from the button to the ViewController.m file while holding down control. This inserted my IBAction method after asking for my buttons id.

myActionButton

然后我在代码中复制了在问题的答案3中指定。我的ViewController.m看起来与此链接有关。

Then I copied in the code specified in response 3 of the question. My ViewController.m looked something link this.

#import "ViewController.h"
@interface ViewController()
@end

@implementation ViewController()
//Some stuff here
@end

@synthesize webView

-(IBAction)myActionButton:(id)sender{
UIPrintInfo *pi = [UIPrintInfo printInfo];
pi.outputType = UIPrintInfoOutputGeneral;
pi.jobName = webView.request.URL.absoluteString;
pi.orientation = UIPrintInfoOrientationPortrait;
pi.duplex = UIPrintInfoDuplexLongEdge;

UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
pic.printInfo = pi;
pic.showsPageRange = YES;
pic.printFormatter = webView.viewPrintFormatter;
[pic presentAnimated:YES completionHandler:^(UIPrintInteractionController *pic2, BOOL completed, NSError *error) {
    // indicate done or error
}];
}

也在我的ViewController.h文件中

Also in my ViewController.h file

#import ...
@interface ViewController : ...
{
IBOutlet UIWebView *webView
}

@property (nonatomic,retain) IBOutlet UIWebView *webView
@end

我没有设置网络视图,因此我不确定100%如何创建它们,但是youtube上的初学者有很多不错的系列,网址为 HackLife87 ,其中显示了如何制作单个视图应用。我认为XCode Tutorial Video#7涉及到设置视图。

I didn't setup the webviews so I am not 100% sure on how they are created, but there is a good series for beginners on youtube at HackLife87 which shows how to make a single view app. I think XCode Tutorial Video #7 involves setting up views.

由于我对XCode和IPad应用程序开发极为环保,因此我通过结合观看中的知识设法解决了问题前面提到的XCode教程视频,然后实施 Hafthor 在stackoverflow上提供的解决方案。

Since I am extremely green to XCode and IPad app development, I managed to solve my problem by combining knowledge from watching the aforementioned XCode tutorial videos and then implementing the solution provided on stackoverflow by Hafthor.

这篇关于iOS启用AirPrint的uiwebview内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆