react-native-fbsdk / Facebook iOS SDK - undefined is not an object (evaluating 'LoginManager.logInWithReadPermissions') - xcode

I am getting an error when trying to use react-native-fbsdk. I assume its some issue with the SDK installation process but I am not sure.
Installation appears to go without error but when trying to use the SDK I am getting this error:
undefined is not an object (evaluating
'LoginManager.logInWithReadPermissions')
Code that is using the SDK:
try {
var result = await LoginManager.logInWithReadPermissions(["public_profile"]);
if (result && result.isCancelled) {
console.log("Login cancelled");
} else {
console.log(
"Login success with permissions: " +
result.grantedPermissions.toString()
);
}
} catch (e) {
console.error(e.message);
}
Installation instructions:
npm install react-native-fbsdk
react-native link react-native-fbsdk
cd ios
pod init
// Add "pod 'FacebookSDK'" to pod file
pod install
// Configure Info.plist and AppDelegate.m
The first 2 commands are specified here: https://github.com/facebook/react-native-fbsdk
The rest of the process is specified here: https://developers.facebook.com/docs/ios/getting-started/#settings
Does anyone have any idea what might be going wrong?
Thanks
Environment:
- macOs High Sierra
- XCode (10.1)
- FacebookSDK (4.38.0)
- react (16.6.1)
- react-native (0.57.5)
- react-native-fbsdk (0.8.0)
There is another unresolved question from someone who appears to have the same problem but he did not specify his installation process or package versions.
Facebook SDK react LoginManager.logInWithReadPermissions undefined is not an object

You have to run react-native link react-native-fbsdk, and check in your native project (ios or android) if it is linked successfully, if not, then do it manually.
1. go to Library file under your project, and right click to choose 'Add files to "Your project". and choose react-native-fbsdk =>ios => RCTFBSDK.xcodepro.
2. add libRCTFBSDK.a to your 'Linked Franmework and Libraray'.
It should work, otherwise check your version of the SDK, since the least version has changed something.

Here is my install procedure. it's work.
1. Install react-native-fbsdk
react-native install react-native-fbsdk
2. Install SDK
Add following lines to ios/PodFile and execute pod install
pod 'FBSDKLoginKit'
pod 'FBSDKShareKit'
If no FBSDKShareKit will build failed with: fatal error: 'FBSDKShareKit/FBSDKShareKit.h' file not found
3. Set Info.plist
Add following lines to ios/Project Name/Info.plist (According to https://developers.facebook.com/docs/ios/getting-started/)
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb369704160457623</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>Your facebook app id</string>
<key>FacebookDisplayName</key>
<string>Your app name</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-share-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
Replace FacebookAppID, FacebookDisplayName key values to you actually use.
4. Modify AppDelegate.m
According to https://developers.facebook.com/docs/ios/getting-started/.
// AppDelegate.m
#import <FBSDKCoreKit/FBSDKCoreKit.h> // Add this line
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions]; // Add this line
// Add any custom logic here.
return YES;
}
// Add following lines
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]
];
// Add any custom logic here.
return handled;
}
5. Modify App.js
Import LoginManager at header.
Add login() function to call LoginManger.logInWithReadPermissions().
Add component to at render().
App.js as following
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* #format
* #flow
*/
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View, TouchableOpacity } from 'react-native';
import { LoginManager } from "react-native-fbsdk";
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
android:
'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
type Props = {};
export default class App extends Component<Props> {
login() {
LoginManager.logInWithReadPermissions(["public_profile"]).then(
function (result) {
if (result.isCancelled) {
console.log("Login cancelled");
} else {
console.log(
"Login success with permissions: " +
result.grantedPermissions.toString()
);
}
},
function (error) {
console.log("Login fail with error: " + error);
}
);
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to React Native!</Text>
<Text style={styles.instructions}>To get started, edit App.js</Text>
<Text style={styles.instructions}>{instructions}</Text>
<TouchableOpacity onPress={this.login.bind(this)}>
<Text>FBLogin</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
6. Run
react-native run-ios
7. My environment:
React Native Environment Info:
Binaries:
Node: 11.2.0 - /usr/local/bin/node
Yarn: 1.12.3 - /usr/local/bin/yarn
npm: 6.4.1 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
Android SDK:
API Levels: 23, 24, 25, 26, 27, 28
Build Tools: 23.0.1, 23.0.3, 24.0.1, 25.0.0, 26.0.1, 26.0.2, 26.0.3, 27.0.1, 27.0.3, 28.0.2, 28.0.3
System Images: android-23 | Intel x86 Atom_64, android-23 | Google APIs Intel x86 Atom_64, android-28 | Google Play Intel x86 Atom
IDEs:
Android Studio: 3.2 AI-181.5540.7.32.5056338
Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmPackages:
react: 16.6.1 => 16.6.1
react-native: 0.57.7 => 0.57.7
npmGlobalPackages:
react-native-cli: 2.0.1
react-native-git-upgrade: 0.2.7
react-native-rename: 2.3.2

Related

Flutter: MissingPluginException(No implementation found for method DocumentReference#set on channel plugins.flutter.io/firebase_firestore)

I'm building windows application by flutter, after adding Firebase packages and connect the app to firebase, I had this problem:
Unhandled Exception: MissingPluginException(No implementation found for method DocumentReference#set on channel plugins.flutter.io/firebase_firestore)
I've tried so many solutions, and searched on the web, but unfortunately all solutions are suit Android not Windows!!!
The idea that I work on, is to upload images to firebase storage, and save data in firestore collections.
All firebase services didn't work with me, Authintication, FireStore, and Storage either.
update:
This is my function code:
Future addCategory() async {
await _userCollectionRef.add({
'id': '4328',
'name': cateNameController.text,
'image': image?.path,
});
cateNameController.clear();
image = null;
update();
}
}
And this is my PubSpec.yaml packages code:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
get: ^4.6.5
smooth_page_indicator: ^1.0.0+2
carousel_slider: ^4.1.1
shared_preferences: ^2.0.15
flutter_svg: ^1.1.0
firebase_core: ^1.19.1
firebase_storage: ^10.3.6
firebase_auth: ^3.6.4
firebase_auth_desktop: ^1.0.2
firebase_core_desktop: ^1.0.2
google_sign_in: ^5.3.3
cloud_firestore: ^3.4.5
firebase_messaging: ^12.0.3
image_picker: ^0.8.5+3
image_picker_windows: ^0.1.0+2
file_picker: ^5.0.1
The Initialize in main() :
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
await initialServices();
runApp(const MyApp());
}
Official firebase plugins are not supported on windows yet, try this https://www.youtube.com/watch?v=Tw7L2NkhwPc But this plugin does not have firebase_storage support.

Authentication problem with running ionic app using firebase on native device, everything works fine with live reload

Good morning!
I have a strange problem where i can run & authenticate my user on my ios device perfectly fine running the app using the command below.
ionic capacitor run -l --external
Using an emulator, it works sometimes, though not always.
When I try to deploy the app using Xcode, the app opens and looks normal, but if I try to send authentication requests to firebase, the app just keeps on loading, although the requests are successfully performed.
I first thought the problem was because of using LocalStorage so I rebuilt everything using Ionic Storage. But that didn't help.
I tried different versions of adding the Firebase SDK in Swift or in the Cocoa Pods file but the behaviour doesn't change so I don't believe that this is a issue with a wrong firebase configuration, what is the proper way to do this by the way - or is Ionic doing this for me already?
The output of Xcode doesn't provide any valuable information either.
2021-12-01 11:20:13.990875+0100 App[3162:27661] Writing analzed variants.
2021-12-01 11:20:14.125754+0100 App[3162:27661] KeyboardPlugin: resize mode - native
⚡️ Loading app at capacitor://localhost...
2021-12-01 11:20:14.552490+0100 App[3162:27661] Writing analzed variants.
⚡️ WebView loaded
⚡️ [log] - Angular is running in development mode. Call enableProdMode() to enable production mode.
⚡️ [log] - null
⚡️ To Native -> App addListener 60635511
2021-12-01 11:20:21.393141+0100 App[3162:27661] [Accessibility] WKContentView[#] set up: # pid: # MACH_PORT -830404096
login-function
loginWithEmail() {
let email: string = this.loginForm.get("email").value;
let password: string = this.loginForm.get("password").value;
this.loadingService.present({
message: "Logging in . . ."
});
this.authService
.loginWithEmail(email, password)
.then((result) => {
this.authService.SetUserData(result.user)
this.resetLoginForm();
this.loginSuccess();
this.router.navigateByUrl("/tabs/intensity");
})
.catch(error => {
console.log(error);
this.loginFailed(error);
});
}
login-success
loginSuccess() {
this.loadingService.dismiss();
this.toastService.present({
message: "Welcome back!",
duration: 3000,
color: "secondary"
});
}
login-with-email
import { AngularFireAuth } from "#angular/fire/compat/auth";
...
async loginWithEmail(email: string, password: string) {
return await this.afAuth.signInWithEmailAndPassword(email, password);
}
set user-data function
SetUserData(user) {
this.user = user;
const userRef: AngularFirestoreDocument<any> = this.afs.doc(`users/${user.uid}`);
const userData: User = {
uid: user.uid,
email: user.email,
displayName: user.displayName,
photoURL: user.photoURL,
emailVerified: user.emailVerified
}
return userRef.set(userData, {
merge: true
})
}
Running it multiple times some times I get this error.
API error: <_UIKBCompatInputView: 0x7fb965726040; frame = (0 0; 0 0); layer = <CALayer: 0x600002f718a0>> returned 0 width, assuming UIViewNoIntrinsicMetric
I am really stuck on this and would appreciate any help. Thank you & kind regards.
Ionic 6.18.1
Angular 12.1.5
Xcode Version 13.1 (13A1030d)

Nativescript throwing Thread 1: EXC_BAD_ACCESS (code=1, address=0x1edf38) in Xcode only

I'm getting an error after upgrading to NS 7 and building in xcode. I can build successfully from the CLI, run the app and everything is fine but when I build in xCode and run on physical device or simulator and try to log in, I get this error.
In the log outputs self = (SAMKeychainQuery*) & password = (NSSTRING *) nil so it's not getting the password value but why would it have access to it when building from the CLI but not Xcode?
I'm running "#nativescript/core": "^7.0.13", "#nativescript/ios": "7.0.6", Xcode 12.
Here is my password textfield:
<TextField
:isEnabled="!processing"
ref="password"
class="input placeholderColor"
hint="Password"
secure="true"
v-model="user.password"
#loaded="passwordTextField"
:returnKeyType="isLoggingIn ? 'done' : 'next'"
fontSize="18"
/>
//login function
async login(user) {
try {
console.log("in login() in authservice")
const loginRequest = await firebase.login({
type: firebase.LoginType.PASSWORD,
passwordOptions: {
email: user.email,
password: user.password,
},
});
const handleLogin = await this.handleLogin(loginRequest);
return handleLogin;
} catch (error) {
return error;
}
}
My login() function isn't even firing when I build from Xcode but again all is well from the CLI.
Completely removing the #nativescript/secure-storage plugin then ns clean and reinstalling secure-storage plugin worked.
Still have no idea why it was working from CLI and not Xcode if the plugin wasn't functioning properly though.

React Native Image component not render image from external url on iOS 14

I upgraded to iOS 14 + XCode-beta Version 12 beta 3 and from that moment React Native Image component not render an image from external URL. On Android, the Image component runs still perfectly.
Here is my code on how I calling an image.
const avatarImageUrl = Config.IMAGE_BASE_URL + this.props.data.avatar;
<Image source={{uri: avatarImageUrl}} style={styles.avatarImage}/>
And this is my Config component:
export default Config = {
API_BASE_URL: 'link-to-api',
IMAGE_BASE_URL: 'link-to-api',
// date when Realm database is updated with fresh API data and
bundled with app
BUILD_DATE: '2020-06-18',
};
And styles
avatarImage: {
flex: 3,
width: '100%',
height: '100%',
borderTopLeftRadius: 10,
borderTopRightRadius: 10,
backgroundColor: '#cccccc',
width: "100%",
marginLeft: 0,
marginRight: 0,
},
It's there anyone who has the same problem with React Native on iOS14?
Thaks
Robert
You can try few things:
A. Use the following package to fix the issue by running:
npm install --save react-native-fix-image
npx react-native-fix-image
Then rebuild project.
Note: each time after reinstalling node_modules you'll have to run npx react-native-fix-image.
B. Upgrade react-native to V0.63.2 then rebuild the project.
I used solution A.

Cannot use import statement outside a module when running android app with firebase

Using nativescript-vue and can't make my app run after upgrading to latest version of nativescript.
"nativescript": {
"id": "xxx",
"tns-ios": {
"version": "6.5.1"
},
"tns-android": {
"version": "6.5.1"
}
},
App.js:
import Vue from "nativescript-vue";
import App from "./components/App";
const firebase = require('nativescript-plugin-firebase')
const {LocalNotifications} = require("nativescript-local-notifications")
firebase.init({
showNotifications: true,
showNotificationsWhenInForeground: true,
onMessageReceivedCallback: (message) => {
console.log('[Firebase] onMessageReceivedCallback:', {message});
LocalNotifications.schedule(
[{
id: 1,
title: message.data.title,
body: message.data.body,
silhouetteIcon: 'res://ic_app_icon',
thumbnail: "res://icon",
forceShowWhenInForeground: true,
notificationLed: true,
channel: i18n.t('messages_about_orders')
}])
.catch(error => console.log("doSchedule error: " + error));
}
}).then(
function () {
console.log("firebase.init done");
},
function (error) {
console.log("firebase.init error: " + error);
}
);
I run tns run android and right after I get Webpack build done in the console, I get these messages and a crash:
nativescript-plugin-firebase: /Users/butaminas/Local Sites/getfast.co.nz-courier-app/platforms/android/.pluginfirebaseinfo not found, forcing prepare!
nativescript-plugin-firebase: running release build or change in environment detected, forcing prepare!
Cannot use import statement outside a module
What could be the problem here? I have another, similar app and it is all working fine.
I figured it out. It was the problem with hooks folder in the project root directory.
I don't know why this happened but after removing the plugin (the hooks directory was not removed) I removed the hooks folder manually and then installed the plugin again - the problem disappeared.

Resources