我在我的Ionic2应用程序中使用了插件:
cordova-plugin-screen-orientation 2.0.1 "Screen Orientation"app.component.ts
import { ScreenOrientation } from '@ionic-native/screen-orientation';
export class MyApp {
constructor(screenOrientation: ScreenOrientation) {
screenOrientation.lock(screenOrientation.ORIENTATIONS.LANDSCAPE);
}
}package.json
"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"
]
}为什么应用程序不能工作?错误:
NotSupportedError: Operation is not supported发布于 2017-08-14 01:35:14
您应该从ionic-native导入Platform,并将ScreenOrientation调用包装在Platform.ready()调用中。ready函数返回一个Promise,当平台准备就绪并且可以调用本机功能时,该and将进行解析。它现在不能为你工作的原因可能是因为当调用函数时平台还没有准备好。
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);
});
}
}https://stackoverflow.com/questions/45661138
复制相似问题