我似乎遇到了本机插件的问题。
logPath:/Users/philipwilson/workspace/ionic/test2/platforms/ios/cordova/console.log
[21:12:05] console.log: Angular is running in the development mode. Call enableProdMode() to enable the production
mode.
[21:12:05] console.log: Ionic Native: deviceready event fired after 542 ms
[21:12:05] console.warn: Native: tried calling Facebook.browserInit, but the Facebook plugin is not installed.
[21:12:05] console.warn: Install the Facebook plugin: 'ionic plugin add cordova-plugin-facebook4'
我尝试了很多东西。
518 ionic cordova plugin add cordova-plugin-facebook4 --variable APP_ID="99999999999" --variable APP_NAME="test2.com"
565 ionic cordova build ios
578 npm install --save @ionic-native/facebook
593 ionic plugin add cordova-plugin-facebook4
594 ionic cordova emulate ios -lc
我遵循了几个例子,但仍然看到离子3和angular4
的问题这是我的信息: 〜/ workspace / ionic / test2 $ ionic info
全球套餐:
@ionic/cli-utils : 1.5.0
Cordova CLI : 7.0.1
Ionic CLI : 3.5.0
本地包裹:
@ionic/app-scripts : 1.3.7
@ionic/cli-plugin-cordova : 1.4.1
@ionic/cli-plugin-ionic-angular : 1.3.2
Cordova Platforms : ios 4.4.0
Ionic Framework : ionic-angular 3.4.2
系统:
Node : v8.0.0
OS : OS X El Capitan
Xcode : Xcode 8.2.1 Build version 8C1002
ios-deploy : 1.8.3
ios-sim : 3.1.1
npm : 5.0.0
我也看过这些例子: https://ionicframework.com/docs/native/facebook/ https://ionicthemes.com/tutorials/about/ionic2-facebook-login
有人有任何帮助吗?
由于 菲尔
答案 0 :(得分:5)
这就是我所做的,请确保在您的app.module.ts
文件上公开Facebook模块。
app.module.ts
import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
import { AboutPage } from '../pages/about/about';
import { ContactPage } from '../pages/contact/contact';
import { HomePage } from '../pages/home/home';
import { TabsPage } from '../pages/tabs/tabs';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { Facebook, FacebookLoginResponse } from '@ionic-native/facebook';
@NgModule({
declarations: [
MyApp,
AboutPage,
ContactPage,
HomePage,
TabsPage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
AboutPage,
ContactPage,
HomePage,
TabsPage
],
providers: [
StatusBar,
SplashScreen,
Facebook,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
在您的home.ts
:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Facebook, FacebookLoginResponse } from '@ionic-native/facebook';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController, private fb: Facebook) {
this.fb = fb
console.log(fb)
this.fb.login(['public_profile', 'user_friends', 'email'])
.then((res: FacebookLoginResponse) =>
console.log('Logged into Facebook!', res)
)
.catch(e => console.log('Error logging into Facebook', e));
this.fb.logEvent(this.fb.EVENTS.EVENT_NAME_ADDED_TO_CART);
}
}
如果您忘记在Facebook
文件中添加app.module.ts
个提供商,则会收到您的错误:"No provider for Facebook!"
作为旁注,请确保使用模拟器或设备测试登录操作,否则它将无法正常工作。
资源: - https://javebratt.com/ionic-2-facebook-login/ - https://ionicframework.com/docs/native/facebook/
答案 1 :(得分:3)
我遇到了同样的问题。 但我正在Ionic的DevApp应用程序上测试我的移动应用程序。 后来我发现,并非Ionic的DevApp都支持所有本机组件。
以下显示了Ionic的DevApp支持的插件列表: List of supported plugins
毕竟我在ios-device上直接测试了我的facebook插件。 即使在xcode-emulator上也是如此。
此致 奥利弗