【问题标题】:Can't get @TeamHive/capacitor-email to work in Ionic 4无法让@TeamHive/capacitor-email 在 Ionic 4 中工作
【发布时间】:2019-07-09 04:24:17
【问题描述】:

https://github.com/TeamHive/capacitor-email 是一个 Capacitor 电子邮件插件,允许您从 Ionic 4 移动应用程序发送电子邮件。我无法让演示在 Android Studio 3.4.1、@ionic/angular 4.0.0-beta.7 和 @capacitor/core 1.1.0 中运行。我收到 5 个构建错误,例如:

ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve project :capacitor-android-plugins.

如果我尝试在入门 Ionic 应用程序中使用 Github 页面上提供的示例代码,我会收到运行时错误:

E/Capacitor/Plugin/Console: ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'requestPermission' of undefined

在我下面的示例代码中,基于 Github 示例代码,console.log 输出 this.email = {},因此 new Email() 返回一个空对象。

  email: Email;

  constructor() { }

  ngOnInit() {
    this.email = new Email();
    console.log('this.email = ' + JSON.stringify(this.email));
  }

  async sendEmail() {

    try {
      await this.email.hasPermission();
    } catch (e) {
      await this.email.requestPermission();
    }

有人让这个电容器插件可以工作吗?

【问题讨论】:

    标签: email ionic-framework ionic4 capacitor


    【解决方案1】:

    要使这个插件工作,你必须编辑生成的 MainActivity 类,并添加add(EmailPlugin.class);,如下所示。

    import com.meetmaestro.hive.capacitor.email.EmailPlugin;
    
    public class MainActivity extends BridgeActivity {
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        // Initializes the Bridge
        this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
          // Additional plugins you've installed go here
          // Ex: add(TotallyAwesomePlugin.class);
          add(EmailPlugin.class);
        }});
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-18
      • 1970-01-01
      • 1970-01-01
      • 2012-01-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多