Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.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
Cordova 应用程序浏览器有时为空/空白_Cordova_Ionic Framework_Inappbrowser_Ionic3 - Fatal编程技术网

Cordova 应用程序浏览器有时为空/空白

Cordova 应用程序浏览器有时为空/空白,cordova,ionic-framework,inappbrowser,ionic3,Cordova,Ionic Framework,Inappbrowser,Ionic3,我正在从事一个项目,在这个项目中,我大量使用应用浏览器中的InAppBrowser来查看不同的文档(PDF、DOC、DOCX)。我是在ochdocs.google.com的帮助下完成这项工作的,文档存储在firebase存储中。 大多数情况下,它在我的Android设备上工作得很好!但有时我得到的只是一个空白的白色屏幕,我必须按下后退按钮关闭appbrowser中的,然后重新打开它以显示文档 在Chrome developer工具中远程调试这种奇怪的行为时,我看到loadstart和loadst

我正在从事一个项目,在这个项目中,我大量使用应用浏览器中的
InAppBrowser
来查看不同的文档(PDF、DOC、DOCX)。我是在och
docs.google.com
的帮助下完成这项工作的,文档存储在
firebase存储中。
大多数情况下,它在我的Android设备上工作得很好!但有时我得到的只是一个空白的白色屏幕,我必须按下后退按钮关闭appbrowser
中的
,然后重新打开它以显示文档

在Chrome developer工具中远程调试这种奇怪的行为时,我看到
loadstart
loadstop
事件被适当地调用:

当我在应用浏览器的空/白
中查看
HTML
时,我看到空
-标记:

我用来在应用浏览器中打开
的代码

import { Injectable } from '@angular/core';
import { Platform } from 'ionic-angular';
import { InAppBrowser, InAppBrowserObject } from '@ionic-native/in-app-browser';
import { ScreenOrientation } from '@ionic-native/screen-orientation';
import { LoaderService } from './loader-service';
import * as firebase from 'firebase';

@Injectable()
export class FirebaseStorageService{
    browserOptions: string;
    browser: InAppBrowserObject;

    constructor(
        private iab: InAppBrowser,
        private loaderService:LoaderService,
        private platform: Platform,
        private screenOrientation: ScreenOrientation
    ){
        this.browserOptions = 'zoom=no,location=no,useWideViewPort=no,hidden=yes,enableViewportScale=yes';
    }

    viewPdf(path: string, loadText?:string):Promise<any>{
        this.showLoader(loadText);
        return new Promise<any>((resolve, reject) => {
            firebase.storage().ref().child(path).getDownloadURL().then(url => {
                let newURL = 'https://docs.google.com/gview?&url=' + encodeURIComponent(url);
                this.startBrowser(newURL);
                resolve();
            })
            .catch(err => {
                if(this.platform.is('cordova')){
                    this.loaderService.dismissLoader();
                }
                reject(err);
            });
        })
    }

    private startBrowser(path:string):void{
        this.browser = this.iab.create(path, '_blank', this.browserOptions);
        if(this.platform.is('cordova')){
            this.handleBrowserSubscriptions();
            this.screenOrientation.unlock();
        }
    }

    private handleBrowserSubscriptions():void{
        let stopSub = this.browser.on('loadstop').subscribe(event => {
            console.log('loadstop', event)
            this.loaderService.dismissLoader();
            this.browser.show();
            stopSub.unsubscribe();
            errorSub.unsubscribe();
        });

        let exitSub = this.browser.on('exit').subscribe(event => {
            console.log('exit:',event)
            this.loaderService.dismissLoader();
            exitSub.unsubscribe();
            this.browser.close();
            this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT);
        });

        let errorSub = this.browser.on('loaderror').subscribe(event => {
            console.log('loaderror', event)
            this.loaderService.dismissLoader();
            this.browser.close();
            this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT);
            stopSub.unsubscribe();
            errorSub.unsubscribe();
        });

        let startSub = this.browser.on('loadstart').subscribe(event => {
            console.log('loadstart', event);
        })
    }
}
从'@angular/core'导入{Injectable};
从“离子角度”导入{Platform};
从“@ionic native/in-app browser”导入{InAppBrowser,InAppBrowserObject};
从'@ionic native/screen orientation'导入{ScreenOrientation};
从“/loader service”导入{LoaderService};
从“firebase”导入*作为firebase;
@可注射()
导出类FirebaseStorageService{
浏览选项:字符串;
浏览器:InAppBrowserObject;
建造师(
私人iab:InAppBrowser,
专用装载机服务:装载机服务,
私有平台:平台,
私人屏幕定向:屏幕定向
){
this.browservoptions='zoom=no,location=no,useWideViewPort=no,hidden=yes,enableViewportScale=yes';
}
viewPdf(路径:string,加载文本?:string):承诺{
这个.showLoader(loadText);
返回新承诺((解决、拒绝)=>{
firebase.storage().ref().child(路径).getDownloadURL().then(url=>{
让newURLhttps://docs.google.com/gview?&url='+encodeURIComponent(url);
this.startBrowser(newURL);
解决();
})
.catch(错误=>{
如果(此.platform.is('cordova')){
this.loaderService.dismissLoader();
}
拒绝(错误);
});
})
}
专用startBrowser(路径:字符串):无效{
this.browser=this.iab.create(路径“_blank”,this.browserviceOptions);
如果(此.platform.is('cordova')){
此.handleBrowserSubscriptions();
这个.screenOrientation.unlock();
}
}
私有句柄浏览器订阅():void{
让stopSub=this.browser.on('loadstop')。订阅(事件=>{
console.log('loadstop',事件)
this.loaderService.dismissLoader();
this.browser.show();
stopSub.unsubscribe();
errorSub.unsubscribe();
});
让exitSub=this.browser.on('exit')。订阅(事件=>{
console.log('退出:',事件)
this.loaderService.dismissLoader();
exitSub.unsubscribe();
this.browser.close();
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.肖像);
});
让errorSub=this.browser.on('loaderror')。订阅(事件=>{
console.log('loaderror',事件)
this.loaderService.dismissLoader();
this.browser.close();
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.肖像);
stopSub.unsubscribe();
errorSub.unsubscribe();
});
让startSub=this.browser.on('loadstart')。订阅(事件=>{
console.log('loadstart',事件);
})
}
}
爱奥尼亚信息:

Cordova CLI:7.0.1
离子框架版本:3.2.0
IONAL CLI版本:2.2.1
爱奥尼亚应用程序库版本:2.2.0
爱奥尼亚应用程序脚本版本:1.3.7
ios部署版本:未安装
ios sim卡版本:未安装
操作系统:Windows 10
节点版本:v6.9.4
Xcode版本:未安装


还有其他人经历过这种情况吗,或者有人知道如何解决这个问题吗?

您正在使用一种方法在Android的web视图中打开文档

解决方案-1: 您当前的网络视图可以进行如下修改:

encodeURI('https://docs.google.com/gview?embedded=true&url=http://www.your-server.com/files/your_file.pdf')
编码完整的url,包括
https://docs.google.com

下面是加载url的另一种方法:


如果这些解决方案中有任何一个不起作用,请尝试下载该文件并在浏览器中打开它

您的
loaderror
是否触发?在使用黑屏时?不,它没有启动。你是否尝试使用AndroidStudio运行你的项目,以检查InApp浏览器插件是否在应用程序的本机部分记录有用的内容?不,我绝对可以尝试!我到底该怎么做?:)