找不到名称“ SFAuthSession”

时间:2019-07-08 02:05:03

标签: ionic4 sfauthenticationsession

我是ionic和cordova插件的新手,我正在尝试使用ionic应用程序中的cordova-plugin-sfauthenticationsession来实现cookie共享。

这是基于此link中提供的文档的代码:

SFAuthSession.start("myScheme://","https://www.facebook.com/",
        function(data){
                console.log(data);
        },function(error){
                console.log(error);
        }
);

问题是,每当我尝试构建我的应用程序时,终端都会显示一个错误,表明找不到SFAuthSession。我不知道我需要导入什么(如果有),因为它没有包含在文档中。希望有人可以帮助我。

P.S。 我在此documentation之后尝试了safari视图控制器,由于它提供了要导入的内容,因此可以正常工作。

1 个答案:

答案 0 :(得分:1)

这是一个常见错误。文档会告诉您如何安装该特定插件,但不会告诉您还需要更新模块文件以包含该插件。

查看此页面:

它说明您需要将插件导入@NgModule中并将其添加到提供者列表中。对于Angular,导入路径应以/ngx结尾。 Angular的更改检测会自动处理。

为此,您可以这样做:

// app.module.ts
import { Camera } from '@ionic-native/camera/ngx';

...

@NgModule({
  ...

  providers: [
    ...
    Camera
    ...
  ]
  ...
})
export class AppModule { }

因此,只需使用该技术导入Ionic Native模块即可,它应该可以工作。

没有Ionic Native包装器时

但是,根据您在下面的评论,现在很明显,此Cordova插件没有Ionic Native包装器。

这意味着您将必须:

  • 无需Ionic Native即可访问
  • 或编写自己的Ionic Native包装器

这篇关于Medium的文章似乎对此有很好的介绍:

Build your first Cordova plugin for Ionic Native – Sangkhim Khun – Medium

您已经超越了我的个人经验,但我正尝试与您一起解决这个问题。

本教程的第三部分有一个有趣的代码片段,可直接访问Cordova插件:

declare var cordova: any;
var success = function(result) {
  alert(JSON.stringify(result, undefined, 2));
}
var failure = function(result) {
  alert(JSON.stringify(result, undefined, 2));
}
cordova.plugins.HelloWorld.coolMethod({
  _sMessage: "Hello World"
}, success, failure);

您将不得不比较Cordova插件的文档以自己适应它以使其正常工作。

或者,如果您继续阅读该教程,则说明如何创建Ionic Native包装器,甚至可以为项目做贡献,以便每个人都可以使用此功能。