NativeScript 8.2:无法读取属性“肖像”;未定义的

发布于 2025-01-14 04:32:01 字数 4068 浏览 0 评论 0原文

我在 NativeScript 版本 8.2 应用程序中使用 NativeScript-Orientation-Free 插件。

我的应用程序可以通过“tns run ios”编译良好,但是 当我尝试设置方向时,运行时出现以下错误并且我的应用程序崩溃

组件

import { Component, OnInit } from '@angular/core';
import * as devOrientation from 'nativescript-orientation-free';

import { Item } from './item'
import { ItemService } from './item.service'

@Component({
  selector: 'ns-items',
  templateUrl: './items.component.html',
})
export class ItemsComponent implements OnInit {
  items: Array<Item>

  constructor(private itemService: ItemService) {}

  ngOnInit(): void {
    this.items = this.itemService.getItems();
    devOrientation.setOrientation("portrait");
  }
}

错误

enter图像描述在这里

包.json

{
  "name": "poc",
  "main": "./src/main.ts",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "@angular/animations": "~13.2.0",
    "@angular/common": "~13.2.0",
    "@angular/compiler": "~13.2.0",
    "@angular/core": "~13.2.0",
    "@angular/forms": "~13.2.0",
    "@angular/platform-browser": "~13.2.0",
    "@angular/platform-browser-dynamic": "~13.2.0",
    "@angular/router": "~13.2.0",
    "@nativescript/angular": "^13.0.0",
    "@nativescript/core": "~8.2.0",
    "@nativescript/theme": "~3.0.2",
    "nativescript-orientation-free": "2.2.5",
    "rxjs": "~7.5.0",
    "zone.js": "~0.11.5"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~13.2.0",
    "@angular/compiler-cli": "~13.2.0",
    "@nativescript/ios": "8.2.1",
    "@nativescript/types": "~8.2.0",
    "@nativescript/webpack": "~5.0.6",
    "@ngtools/webpack": "~13.2.0",
    "typescript": "~4.5.5"
  }
}

Webpack.config.js

const webpack = require("@nativescript/webpack");

module.exports = (env) => {
    webpack.init(env);

    webpack.chainWebpack(config=>{
        config.resolve.alias.set('tns-core-modules/application','@nativescript/core/application');
        config.resolve.alias.set('tns-core-modules/ui/core/view-base','@nativescript/core/ui/core/view-base');    
        config.resolve.alias.set('tns-core-modules/ui/core/view','@nativescript/core/ui/core/view');
        config.resolve.alias.set('tns-core-modules/ui/page','@nativescript/core/ui/page'); 
        config.resolve.alias.set('tns-core-modules/ui/frame','@nativescript/core/ui/frame');
        config.resolve.alias.set('tns-core-modules/ui/page','@nativescript/core/ui/page');
        config.resolve.alias.set('tns-core-modules/ui/enums','@nativescript/core/ui/enums');
      });


    return webpack.resolveConfig();
};

tsConfig.json

{
  "compilerOptions": {
    "module": "esnext",
    "target": "es2017",
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "noEmitHelpers": true,
    "noEmitOnError": true,
    "skipLibCheck": true,
    "lib": ["es2017", "dom"],
    "baseUrl": ".",
    "paths": {
      "~/*": ["src/*"],
      "@/*": ["src/*"]
    }
  },
  "include": ["src/tests/**/*.ts", "src/**/*.ios.ts", "src/**/*.android.ts"],
  "files": ["./src/main.ts", "./references.d.ts", "./src/polyfills.ts"],
  "exclude": ["node_modules", "platforms", "e2e"]
}

我不想使用此付费版本 NativeScript-Orientation。谁能告诉我如何修复或我缺少什么,或者我们有任何替代方法来设置方向吗?

I am using NativeScript-Orientation-Free Plugin in my NativeScript version 8.2 Application.

My app is compiling fine with "tns run ios" but
I am getting below Error on the run time and my app crashes When I am trying to set the orientation

Component

import { Component, OnInit } from '@angular/core';
import * as devOrientation from 'nativescript-orientation-free';

import { Item } from './item'
import { ItemService } from './item.service'

@Component({
  selector: 'ns-items',
  templateUrl: './items.component.html',
})
export class ItemsComponent implements OnInit {
  items: Array<Item>

  constructor(private itemService: ItemService) {}

  ngOnInit(): void {
    this.items = this.itemService.getItems();
    devOrientation.setOrientation("portrait");
  }
}

Error

enter image description here

Package.json

{
  "name": "poc",
  "main": "./src/main.ts",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "@angular/animations": "~13.2.0",
    "@angular/common": "~13.2.0",
    "@angular/compiler": "~13.2.0",
    "@angular/core": "~13.2.0",
    "@angular/forms": "~13.2.0",
    "@angular/platform-browser": "~13.2.0",
    "@angular/platform-browser-dynamic": "~13.2.0",
    "@angular/router": "~13.2.0",
    "@nativescript/angular": "^13.0.0",
    "@nativescript/core": "~8.2.0",
    "@nativescript/theme": "~3.0.2",
    "nativescript-orientation-free": "2.2.5",
    "rxjs": "~7.5.0",
    "zone.js": "~0.11.5"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~13.2.0",
    "@angular/compiler-cli": "~13.2.0",
    "@nativescript/ios": "8.2.1",
    "@nativescript/types": "~8.2.0",
    "@nativescript/webpack": "~5.0.6",
    "@ngtools/webpack": "~13.2.0",
    "typescript": "~4.5.5"
  }
}

Webpack.config.js

const webpack = require("@nativescript/webpack");

module.exports = (env) => {
    webpack.init(env);

    webpack.chainWebpack(config=>{
        config.resolve.alias.set('tns-core-modules/application','@nativescript/core/application');
        config.resolve.alias.set('tns-core-modules/ui/core/view-base','@nativescript/core/ui/core/view-base');    
        config.resolve.alias.set('tns-core-modules/ui/core/view','@nativescript/core/ui/core/view');
        config.resolve.alias.set('tns-core-modules/ui/page','@nativescript/core/ui/page'); 
        config.resolve.alias.set('tns-core-modules/ui/frame','@nativescript/core/ui/frame');
        config.resolve.alias.set('tns-core-modules/ui/page','@nativescript/core/ui/page');
        config.resolve.alias.set('tns-core-modules/ui/enums','@nativescript/core/ui/enums');
      });


    return webpack.resolveConfig();
};

tsConfig.json

{
  "compilerOptions": {
    "module": "esnext",
    "target": "es2017",
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "noEmitHelpers": true,
    "noEmitOnError": true,
    "skipLibCheck": true,
    "lib": ["es2017", "dom"],
    "baseUrl": ".",
    "paths": {
      "~/*": ["src/*"],
      "@/*": ["src/*"]
    }
  },
  "include": ["src/tests/**/*.ts", "src/**/*.ios.ts", "src/**/*.android.ts"],
  "files": ["./src/main.ts", "./references.d.ts", "./src/polyfills.ts"],
  "exclude": ["node_modules", "platforms", "e2e"]
}

i do not want to use this paid version NativeScript-Orientation. can anyone tell me how can I fix or what i am missing or do we have any alternate to set the orientation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

锦欢 2025-01-21 04:32:01

我删除了第三方插件以进行方向设置并像这样设置

UIDevice.currentDevice.setValueForKey(currentOrientation, "orientation");

i removed the third party plugins for orientation and setting it like this

UIDevice.currentDevice.setValueForKey(currentOrientation, "orientation");

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文