I'm in need of your expertise in React Native.
I'm trying to use expo-local-authentication for local fingerprint authentication for my application.
My project was created using expo init command.
I have done the setup as per the documentation and still running into a strange issue:
Below is the error I'm facing for LocalAuthentication.authenticateAsync(options):
Native method ExpoLocalAuthentication.authenticateAsync expects 0
arguments but received 1
Here is the required part of my code:
import * as LocalAuthentication from 'expo-local-authentication';
const authenticate = async () => {
const hasHardwareAsync = await LocalAuthentication.hasHardwareAsync();
if (hasHardwareAsync) {
const supportedAuthentications = await LocalAuthentication.supportedAuthenticationTypesAsync();
if (supportedAuthentications.indexOf(1) !== -1) {
// Finger print supported
const isFingerprintEnrolled = await LocalAuthentication.isEnrolledAsync();
if (isFingerprintEnrolled) {
const options = {
promptMessage: 'Authenticate yourself',
};
try {
// Also tried with await but it throws the same error
// await LocalAuthentication.authenticateAsync(options)
LocalAuthentication.authenticateAsync(options).then(result => {
// I never get inside this block
console.warn(result)
})
.catch(error => {
console.warn('Authentication Error: ', error)
})
} catch (error) {
console.warn(error)
}
}
}
}
}
Not sure what I'm missing. Seems like there is no information available about the error. I also tried to run the LocalAuthentication.authenticateAsync() without any arguments but it still throws the same error.
Any help on what could be the root cause of the issue and how can I resolve it or any other alternative for local authentication would be highly appreciated.
Update your app to the latest version of expo (38 in my case) and to the latest version of expo-local-authentication, and the error goes away.
Related
I recently started developing an app using Flutter and Firebase. I use Firebase Emulator to test Authentication and Cloud Functions. Most of my code is in the Firebase Cloud Functions which I use for all CRUD for Firestore and RTDB. While adding some new features, I got this error in my app. I tried searching a lot but could not find any solution. The following is the error is receive:
An error occured while calling function profile-get
Error Details: null
Message: An internal error has occurred, print and inspect the error details for more information.
Plugin: firebase_functions
Stacktrace: null
My API class in Flutter:
class Api {
Api(this.functions);
final FirebaseFunctions functions;
static Api init() {
FirebaseFunctions functions = FirebaseFunctions.instance;
if (emulator) functions.useFunctionsEmulator(origin: host);
return Api(functions);
}
Future<ApiResult> call(String name, {
Map<String, dynamic> parameters,
}) async {
try {
HttpsCallable callable = functions.httpsCallable(name);
HttpsCallableResult results = await callable.call(parameters);
return ApiResult(new Map<String, dynamic>.from(results.data));
} on FirebaseFunctionsException catch (e) {
print('An error occurred while calling function $name.');
print('Error Details: ${e.details}\nMessage: ${e.message}\nPlugin: ${e.plugin}\nStacktrace: ${e.stackTrace}');
return ApiResult({
'status': 'error',
'message': 'An error occured',
'code': 'unknown'
});
}
}
static String get host => Platform.isAndroid ? 'http://10.0.2.2:2021' : 'http://localhost:2021';
}
I tried running the functions directly from their local URL and they work fine.
As mentioned in the comments defore you are reating a cloud function with onRequest. Those are not callable using an SDK but only trough https URL.
To create a callable function that you can call trough Firebase SDKs you would need to refactor your functions to use the onCall.
It should look something like this:
exports.yourFunctionName= functions.https.onCall((data, context) => {
// receive the data
const text = data.text;
// return a response
return {
test:'test'
}
});
Here you have more information how the callable functions work.
Are you using a different region than the standard us-central1? This is often the case, so you need to change the region you are calling from
HttpsCallable callable = FirebaseFunctions.instanceFor(region:"your_region").httpsCallable(name);
I'm having issues trying to get the InAppPurchases to work in my React Native app using Expo. https://docs.expo.io/versions/latest/sdk/in-app-purchases
This is a bare workflow app that I ejected from a standard Expo app.
I made sure to follow the install instructions here carefully: https://docs.expo.io/bare/installing-unimodules/
I did test if unimodules was properly installed:
import { Constants } from "react-native-unimodules";
useEffect(() => {
alert("installed: " + JSON.stringify(Constants.systemFonts));
}, []);
The code above worked.
I'm using react-native-unimodules version 0.11.0.
Here's my code:
useEffect(() => {
(async function init() {
try {
const connect_res = await connectAsync();
alert("connect: " + JSON.stringify(connect_res));
} catch (err) {
alert("general error for connect async: " + err);
}
})();
}, []);
This is in the App.js entrypoint file. It always returns undefined for the connect_res so I assume this is the reason why I couldn't get any of the code to work.
Just below connectAsync() I have the following. This one also doesn't return anything:
setPurchaseListener(({ responseCode, results, errorCode }) => {
if (responseCode === IAPResponseCode.OK) {
results.forEach((purchase) => {
if (!purchase.acknowledged) {
alert("purchase successful!");
finishTransactionAsync(purchase, true);
}
});
}
if (responseCode === IAPResponseCode.USER_CANCELED) {
alert("user cancelld!");
} else if (responseCode === IAPResponseCode.DEFERRED) {
alert("user does not have permission to buy");
} else {
alert("something went wrong: " + errorCode);
}
});
Then on my payment screen I have the following:
import { getProductsAsync, purchaseItemAsync } from "expo-in-app-purchases";
This is the code for the payment button:
const makePayment = async () => {
alert("now making payment...");
try {
const items = Platform.select({
ios: ["abc"],
android: ["my-sub-id", "sku-my-sub-id"],
});
alert("items: " + JSON.stringify(items));
const products = await getProductsAsync(items);
alert("products: " + JSON.stringify(products));
if (products.results.length > 0) {
alert("found products!");
await purchaseItemAsync("my-sub-id");
alert("done making payment!");
} else {
alert("no products..");
}
} catch (err) {
alert("error occured while trying to purchase: " + err);
}
};
In this case, getProductsAsync() does return something resembling the format the results should be. But it doesn't return any of the subscriptions I created (I copied the product ID value listed in that column and I supplied it to both getProductsAsync and purchaseItemAsync. I also supplied the url version which basically just has a prefix of sku-:
I also enabled licensing testing for the email I'm using in Google Play:
Do note that I'm uploading the .aab file to Google Play on the internal testing track then I install it using this URL format: https://play.google.com/apps/test/com.myname.appname/versionNumber
But when I open that link, it seems like google play is detecting it as an old version even though its the latest one. The changes I've made shows up though so I'm pretty sure that's the correct install URL.
What else could I be missing?
For anyone having the same problem. all you have to do is add this on your android/app/src/main/AndroidManifest.xml file:
<uses-permission android:name="com.android.vending.BILLING" />
It wasn't mentioned in the docs at the time of this post, and it doesn't get automatically added when you install a module. Might help save you the headache if you assume the same is true for all Expo modules.
expo-camera: "^8.0.0"
sdkVersion: "36.0.0"
Hello people, when i try:
import { Camera } from 'expo-camera';
...
const cameraIsAvailable = await Camera.isAvailableAsync()
const availablesCameraTypes = await Camera.getAvailableCameraTypesAsync()
console.log("cameraIsAvailable: ", cameraIsAvailable)
console.log("availablesCameraTypes: ", availablesCameraTypes)
i get the fallowing errors:
expo-camera.isAvailableAsync is not available on android, are you sure you've linked all the native dependencies properly?
The method or property expo-camera.getAvailableCameraTypesAsync is not available on android, are you sure you've linked all the native dependencies properly?
the problem just disappear when i remove:
state = {
...
cameraType: Camera.Constants.Type.front,
};
...
<Camera
type={this.state.cameraType}
flashMode={flashMode}
style={styles.preview}
ref={camera => this.camera = camera}
/>
and change it by:
state = {
...
cameraType: Camera.Constants.Type.back,
};
and i change "cameraType" by
componentDidMount = () => {
this.props.navigation.addListener('didFocus', async () => {
await setTimeout(() => {
this.setState({ cameraType: Camera.Constants.Type.front })
}, 100)
});
}
it seems its an error from expo-camera...
so when i try to call these methods:
const cameraIsAvailable = await Camera.isAvailableAsync()
const availablesCameraTypes = await Camera.getAvailableCameraTypesAsync()
i get following errors: errors: expo-camera.isAvailableAsync and expo-camera.getAvailableCameraTypesAsync is not available on android
The methods you're trying to use, Camera.isAvailableAsync and Camera.getAvailableCameraTypesAsync are marked in the documentation as Web only, so calling them will only work, well, on Web.
In code run in react-native context (as opposed to browser context) just check permissions and you should be good to go!
I am building an Android app using Ionic. And using the following feathers_client.js
const feathers = require('#feathersjs/feathers');
const socketio = require('#feathersjs/socketio-client');
const auth = require('#feathersjs/authentication-client');
const io = require('socket.io-client');
const socket = io('http://mydomain.example:3030');
const feathers_client = feathers();
feathers_client
.configure(socketio(socket))
.configure(auth({ storage: window.localStorage }));
module.exports = feathers_client;
When I run the app at the browser it works fine. But when I run it at an Android device I only get "NotAuthenticated".
I am assuming this is happening because FeathersJS stores the JWT token at window.localStorage and this is not available at the Android app userspace.
Two questions:
1) Is there any way to tell FeathersJS to store this token somewhere else?
2) If not, anyone faced this situation and may provide me a solution?
By the way, this is my code for authenticating:
export class SSHSettingsPage implements OnInit {
public inputEmail: string;
public inputPassword: string;
constructor() { }
ngOnInit() {
}
public performLogin($event) {
let authObj: object = { "strategy": "local", "email": this.inputEmail, "password": this.inputPassword};
client.authenticate(authObj)
.then(res => {
console.log(res);
window.localStorage.setItem("user",JSON.stringify(res.user));
window.location.href = "/download";
})
.catch(err => {
console.log(err);
window.location.href = "/login-error";
})
}
}
As mentioned in the configuration API the storage option can be passed an instance of the React Native AsyncStorage:
import {AsyncStorage} from 'react-native';
// Available options are listed in the "Options" section
app.configure(auth({
storage: AsyncStorage
}))
I'm trying to incorporate Twilio voice using the react-native-twilio-programmable-voice package. My app loads on ios, but when running on android I get this error message
Attempt to invoke virtual method 'boolean
android.app.Activity.shouldShowRequestPermissionRationale' on a null
object reference
screenshot here
I've included <uses-permission android:name="android.permission.RECORD_AUDIO" /> in AndroidManifest.xml
and none of the TwilioVoice related functions are called until 4 or 5 screens into the app.
Been scratching my head for a few days now, any help is greatly appreciated.
Code snippet of my Twilio helper class:
import TwilioVoice from 'react-native-twilio-programmable-voice';
import {Platform} from 'react-native';
import config from '../config/Config';
export default class Voip{
constructor(props) {
this.state = {
};
}
async setupDeviceWithToken(accessToken){
console.log('V32: setup device', accessToken);
TwilioVoice.addEventListener('deviceReady', () => this.deviceReadyHandler());
TwilioVoice.addEventListener('deviceNotReady', () => this.deviceNotReadyHandler());
TwilioVoice.addEventListener('connectionDidConnect', () => this.connectionDidConnectHandler());
TwilioVoice.addEventListener('connectionDidDisconnect', () => this.connectionDidDisconnectHandler());
if(Platform.OS === 'ios')
{
TwilioVoice.addEventListener('callRejected', this.callRejected());
} else if (Platform.OS === 'android')
{
TwilioVoice.addEventListener('deviceDidReceiveIncoming', this.deviceDidReceiveIncomingHandler());
}
var success;
try {
success = await TwilioVoice.initWithToken(accessToken);
console.log('V36: ', success);
//return success;
}
catch(err){
console.log('V40: ' ,err);
return err;
}
// if(Platform.OS === 'ios')
// {
try {
TwilioVoice.configureCallKit({
appName: 'VoipApp' // Required param
})
console.log('V50: ios success');
//return 'success';
}
catch (err) {
console.log('V54: ',err);
return err;
}
// }
return success;
}
I've been using the same library to handle the integration with React Native. I feel your pain with attempting this integration because there are a lot of hiccups along the way. I ran into this problem when letting the Android side handle permissions.
I discovered that permissions can instead be handled through React Native on Android. I commented out the permission calls on Android and switched over to the React Native implementation, and that worked for me.
There have been many updates since this question was posted so the user must take care in what versions are being used between Twilio Voice for iOS (Pods), Android, and the React Native wrapper. I ended up forking the library to control what is merged because every aspect is under active development.
async function requestMicrophonePermission() {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
{
'title': `${name} Microphone Permission`,
'message': `${name} needs access to your microphone
'so you can talk.`
}
)
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("Microphone permission granted")
} else {
console.log("Microphone permission denied")
}
} catch (err) {
console.warn(err)
}
}
Best of luck!
I had the same issue and after examining the code in detail, I figured out that the permission request is been made in TwilioVoiceModule's constructor and at that time, ActivityCompat might not have been initialized probably (BTW, I am an iOS developer and haven't worked much on Android). So I created a #ReactMethod that asks for permission and called that method in ReactNative after I get to the call screen.
Something like this:
#ReactMethod
public void askForMicrophones() {
if (!checkPermissionForMicrophone()) {
requestPermissionForMicrophone();
}
}
I have the same type of issue but slightly different Attempt to invoke interface method 'expo.modules.interfaces.barcodescanner.BarCodeScannerInterface expo.modules.interfaces.barcodescanner.BarCodeScannerProviderInterface.createBarCodeDetectorWithContext(android.content.Context)' on a null object reference
ℹ️ After downgrading expo-camera from 12.1.0 to 12.0.3, the issue does not seem to show anymore.
I solve this problem by starting a new react native project because it save me all the stress of looking for unknown solutions