ios - Cordova ionic 打印插件在 iOs 中发送 nil

标签 ios ionic3 cordova-plugins

我需要在 iOs 和 Android 中打印 webview。 在 Android 中一切正常,而在 iO 中,打印对话框打开但不显示任何内容。

调试插件 native 代码,我在APPPrinter.m中发现对这些行的多次调用

dispatch_sync(dispatch_get_main_queue(), ^{
            item = [[UIMarkupTextPrintFormatter alloc]
                    initWithMarkupText:content];
        });

第一次content包含webview html,后者被设置为nil,正常吗? 这是用于调用插件的代码片段。

this.http.get('../../assets/css/print.css', { responseType: 'text' }).subscribe(
      cssFile => {

        let PDF_HTML = `<style>${cssFile}</style> ${content}`;
        let html = '<html>';
        html += '<head>';
        html += '<style>';
        html += cssFile;
        html += '</style>';
        html += '</head>';
        html += '<body>';
        html += content;
        html += '</body>';
        html += '</html>';
        this.printer.print(html, options)
          .then(res => {
            console.log(res);
          },
            err => {
              console.error(err);
            });
      },
      err => {
        console.error(err);
      });

这是我的 ionic 信息输出:

cli packages: (C:\Users\xxxxxxxxx\AppData\Roaming\nvm\v10.16.0\node_modules)

    @ionic/cli-utils  : 1.19.2
    ionic (Ionic CLI) : 3.20.0

global packages:

    cordova (Cordova CLI) : not installed
    Gulp CLI              : [10:40:17] CLI version 3.9.1 [10:40:17] Local version 3.9.1

local packages:

    @ionic/app-scripts : 3.2.4
    Cordova Platforms  : android 7.1.4
    Ionic Framework    : ionic-angular 3.9.8

System:

    Android SDK Tools : 26.1.1
    Node              : v10.16.0
    npm               : 6.9.0 
    OS                : Windows 10

Environment Variables:

    ANDROID_HOME : C:\Users\xxxxxxxxx\AppData\Local\Android\Sdk   

Misc:

    backend : pro

打包 json:

"@ionic-native/printer": "4.20.0"
"cordova-plugin-printer": "0.8.0",

感谢您的支持!

ps。 我已经打开了相应的问题 here

最佳答案

对于那些可能遇到模拟问题的人: 问题似乎在于 css 规则,其形式为:

page-break-<xxx>

break-<xxx> 替换分页符解决了问题。

MDN WebDocs 所示page-break现已弃用。

奇怪的是,Android 无法识别 break- 语法,但这超出了这个问题的范围。

关于ios - Cordova ionic 打印插件在 iOs 中发送 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59108752/

相关文章:

ios - SMS WatchKit 多个数字分隔符

iOS 通过 XCode 将应用程序提交到 App Store 到国外 iTunes Connect 帐户

objective-c - 滚动后单元格变空。 (X代码)

iphone - 创建一个应用程序来访问 iOS 用户照片中的所有图像?

android - Ionic 3 Android 构建错误(找不到 support-v4.jar)

cordova - Chrome 自定义选项卡和cordova

cordova - 将 Cordova 插件更新到特定版本

angular - Ionic-3 找不到管道

android - ionic 3 android状态栏没有图标显示

ios - 无法运行 bms-samples-cordova-hellopush - 未找到 bms_samples_cordova_push-Swift.h 文件