I'm using the plugin in my Ionic2 application:
cordova-plugin-screen-orientation 2.0.1 "Screen Orientation"
import { ScreenOrientation } from '@ionic-native/screen-orientation';
export class MyApp {
constructor(screenOrientation: ScreenOrientation) {
screenOrientation.lock(screenOrientation.ORIENTATIONS.LANDSCAPE);
}
}
"cordova": {
"plugins": {
"cordova-plugin-console": {},
"cordova-plugin-device": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-whitelist": {},
"ionic-plugin-keyboard": {},
"cordova-plugin-http": {},
"cordova-plugin-screen-orientation": {}
},
"platforms": [
"android",
"browser",
"ios"
]
}
Why the application not working ? error:
NotSupportedError: Operation is not supported
答案 0 :(得分:1)
您应该从ionic-native
导入Platform
并将ScreenOrientation
来电包裹在Platform.ready()
来电。 ready
函数返回Promise
,该平台在平台准备就绪时可以解析,并且可以调用本机功能。它现在不适合你的原因可能是因为在调用函数时平台还没有准备好。
import { Platform } from 'ionic-angular';
import { ScreenOrientation } from '@ionic-native/screen-orientation';
export class MyApp {
constructor(private screenOrientation: ScreenOrientation, private platform: Platform) {
platform.ready().then(() => {
this.screenOrientation.lock(screenOrientation.ORIENTATIONS.LANDSCAPE);
});
}
}