I’m trying to get a similar app running and I’m having problems I can’t seem to solve. I’m hoping you guys can help me out.
My app consists of 2 pages with the sidemenu starter template. It’s very similar to the Ionic Go tutorial Josh posted.
Here’s my ionic info output
global packages:
@ionic/cli-utils : 1.5.0
Cordova CLI : 7.0.1
Ionic CLI : 3.5.0
local packages:
@ionic/app-scripts : 2.0.1
@ionic/cli-plugin-cordova : 1.4.1
@ionic/cli-plugin-ionic-angular : 1.3.2
Cordova Platforms : android 6.2.3 browser 4.1.0 ios 4.4.0
Ionic Framework : ionic-angular 3.5.0
System:
Node : v6.9.2
OS : Windows 8.1
Xcode : not installed
ios-deploy : not installed
ios-sim : not installed
npm : 3.10.9
My package.json:
{
"name": "CameraTest",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"@angular/common": "4.1.3",
"@angular/compiler": "4.1.3",
"@angular/compiler-cli": "4.1.3",
"@angular/core": "4.1.3",
"@angular/forms": "4.1.3",
"@angular/http": "4.1.3",
"@angular/platform-browser": "4.1.3",
"@angular/platform-browser-dynamic": "4.1.3",
"@ionic-native/camera-preview": "^4.0.0",
"@ionic-native/core": "3.12.1",
"@ionic-native/splash-screen": "3.12.1",
"@ionic-native/status-bar": "3.12.1",
"@ionic/storage": "2.0.1",
"cordova-android": "^6.2.3",
"cordova-browser": "^4.1.0",
"cordova-ios": "^4.4.0",
"cordova-plugin-camera-preview": "^0.9.0",
"cordova-plugin-console": "^1.0.5",
"cordova-plugin-device": "^1.1.4",
"cordova-plugin-splashscreen": "^4.0.3",
"cordova-plugin-statusbar": "^2.2.2",
"cordova-plugin-whitelist": "^1.3.1",
"ionic-angular": "3.5.0",
"ionic-plugin-keyboard": "^2.2.1",
"ionicons": "3.0.0",
"rxjs": "5.4.0",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.12"
},
"devDependencies": {
"@ionic/app-scripts": "2.0.1",
"@ionic/cli-plugin-cordova": "1.4.1",
"@ionic/cli-plugin-ionic-angular": "1.3.2",
"typescript": "2.3.4"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"cordova-plugin-camera-preview": {},
"cordova-plugin-console": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-whitelist": {},
"ionic-plugin-keyboard": {}
},
"platforms": [
"android",
"browser",
"ios"
]
}
}
I’ve added this to my config.xml, as suggested in the Ionic Native docs for iOS 10+:
<config-file parent="NSCameraUsageDescription" platform="ios" target="*-Info.plist">
<string>Allow the app to use your camera</string>
</config-file>
My HomePage has nothing special. My PreviewPage ts file:
import { HomePage } from './../home/home';
import { CameraPreview, CameraPreviewOptions } from '@ionic-native/camera-preview';
import { Component, OnInit } from '@angular/core';
import { NavController } from 'ionic-angular';
@Component({
selector: 'page-preview',
templateUrl: 'preview.html',
})
export class PreviewPage implements OnInit {
constructor(public navCtrl: NavController, private cameraPreview: CameraPreview) {
}
ngOnInit(): void {
const cameraPreviewOpts: CameraPreviewOptions = {
x: 0,
y: 0,
width: window.screen.width,
height: window.screen.height,
camera: this.cameraPreview.CAMERA_DIRECTION.BACK,
tapPhoto: false,
previewDrag: false,
toBack: true,
alpha: 1
};
this.cameraPreview.startCamera(cameraPreviewOpts).then(
(res) => {
console.log("startCamera success", res);
},
(err) => {
console.log("startCamera error", err)
});
}
exit(){
console.log("go home");
this.navCtrl.setRoot(HomePage);
}
switchCamera(){
this.cameraPreview.switchCamera();
}
ionViewWillLoad(){
document.getElementsByTagName('html')[0].style.visibility = 'hidden';
}
ionViewWillLeave(){
document.getElementsByTagName('html')[0].style.visibility = 'visible';
}
}
I’ve imported CameraPreview to my app.module.ts:
import { CameraPreview } from '@ionic-native/camera-preview';
...
providers: [
StatusBar,
SplashScreen,
CameraPreview,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
So now when I test in the browser on my PC, there’s no camera so I don’t expect to see that but all the elements in the DOM have transparent backgrounds, plus @Gunnarkd’s suggestion to use the ionViewWillLoad/ionViewWillLeave sets the visibility on the html element.
I upload my app with ionic upload and test the app in the Ionic View app… and no camera preview. 
Does the CameraPreview just not work in Ionic View?
Any help would be appreciated! 