1

我正在尝试找到一种使用电容器打开设置/首选项应用程序的方法,但我没有成功。

App.canOpenUrl({ url: 'com.apple.Preferences' })失败并显示错误消息-canOpenURL: failed for URL: "com.apple.Preferences" - error: "Invalid input URL"

我不确定我是否做错了,或者是否甚至可以使用电容器打开本机应用程序......?

这篇文章展示了如何打开 facebook 应用程序,但没有关于原生应用程序

4

2 回答 2

2

对于有同样问题的人
安装: cordova-open-native-settings

$ npm install cordova-open-native-settings
$ npm install @ionic-native/open-native-settings
$ ionic cap sync

app.module.ts

// ...
import { OpenNativeSettings } from '@ionic-native/open-native-settings/ngx';

@NgModule({
  declarations: [
    // ...
  ],
  entryComponents: [
    // ...
  ],
  imports: [
    // ...
  ],
  providers: [
    // ...
    OpenNativeSettings,
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}

whatever.page.ts

// ...
import { OpenNativeSettings } from '@ionic-native/open-native-settings/ngx';

@Component({
  selector: 'app-whatever',
  templateUrl: './whatever.page.html',
  styleUrls: ['./whatever.page.scss'],
})
export class PopoverComponent implements OnInit {

  constructor(
    // ...
    private nativeSettings: OpenNativeSettings
  ) { }

  phoneSettings() {
    this.nativeSettings
      .open('settings')
      .then( res => {
        console.log(res);
      })
      .catch( err => {
        console.log(err);
      })
  }
}

于 2020-05-13T12:12:12.903 回答
1

现在有一个电容器插件,电容器本机设置

它类似于 cordova 插件,但您必须为每个平台(iOS 或 Android)调用正确的函数,而不是为两者使用单个函数。

于 2021-10-08T17:40:48.633 回答