React-Native Firebase Phone Auth freezes iPhone - ios

I want to sign the user in by phoneNumber in react-native. On Android this code snippet works neat. But on iOS always when I start this function the emulator freezes. I am trying to use this code Auth-Example I am using the react-native-firebase library.
openPhoneVerification() {
firebase
.auth()
.signInWithPhoneNumber(this.state.phoneNumber)
.then(confirmResult =>
this.props.navigation.navigate("PhoneVerification", {
confirmResult
})
)
// Wrong number - https://firebase.google.com/docs/reference/js/firebase.auth.Auth#signInWithPhoneNumber
.catch(error =>
Alert.alert(
"Number not valid",
"Please check your number and type in again",
[
{
text: "OK",
style: "cancel"
}
],
{ cancelable: true }
)
);
}

Solution for anyone encountering the same issue:
Make sure that the name given to your APN matches the app name

Related

How can I add 3 custom sounds in react native iOS?

I want to add 3 custom sounds in react native iOS.
Have any of you ever solved it?
Currently, when I test the FCM Notification by adding and grouping a voice file (.wav) to the iOS project folder, one of the added sounds is coming out.
For example, suppose you have sound files sound01, sound02, sound03, when the backend sends an FCM notification, I want the specified sound to sound at that time.
I solved Android but I don't know how to set in iOS environment.
is iOS has channel like android?
I solved it with the code below in the source receiving Firebase Cloud Messaging (FCM).
// remote message processing function
const sendLocalNotificationWithSound = remoteMessage => {
if (Platform.OS === 'ios') {
PushNotificationIOS.addNotificationRequest({
id: remoteMessage.notification.notificationId
? remoteMessage.notification.notificationId
: new Date().toString(),
title: remoteMessage.notification.title,
subtitle: remoteMessage.notification.message
? remoteMessage.notification.message
: '',
body: remoteMessage.notification.body,
sound: remoteMessage.notification.sound
})
} else {
PushNotification.localNotification({
channelId: remoteMessage.notification.android.channelId,
id: remoteMessage.notification.notificationId
? remoteMessage.notification.notificationId
: new Date().toString(),
title: remoteMessage.notification.title,
message: remoteMessage.notification.body,
soundName: remoteMessage.notification.android.sound,
playSound: true,
smallIcon: 'ic_stat_ic_notification',
color: '#FFFFFF',
largeIcon: '',
largeIconUrl: '',
vibrate: true,
groupSummary: true
})
}
}
// remote message receiving
React.useEffect(() => {
const getMessage = messaging().onMessage(remoteMessage => {
sendLocalNotificationWithSound(remoteMessage)
})
return () => getMessage()
}, [])
First, the react-native-push-notification and #react-native-community/push-notification-ios libraries must be installed.
react-native-push-notification
#react-native-community/push-notification-ios
function messaging() in code is #react-native-firebase/messaging library.
you have to import module like:
import messaging from '#react-native-firebase/messaging'
on head in code
The official documentation for react-native FCM (firebase cloud messaging) is here -> REACT NATIVE FIREBASE
FCM sending side JSON sample file
(I test with postman)
{
"to": "your fcm token here",
"notification": {
"title": "your notification title",
"body": "your notification description",
"sound": "your notification sound name (Runs on iOS)",
"android_channel_id": "your android channel id here (Runs on Android)",
"priority": "high",
"contentAvailable": true,
"mutableContent": 1
},
"data": {
... // if you need data property
}
}

Stripe Flutter can't display payment in IOS simulator

I'm working Flutter Stripe with this library : https://pub.dev/packages/flutter_stripe.
This is the function from my bloc to create successfully payment intent and display the payment sheet.
paymentSink.add(Status.Loading);
logData(key, 'Stripe Pay');
//create payment intent
var response = await paymentRepository.createPaymentIntent(200, 'USD');
paymentSink.add(Status.Successful);
var paymentIntentData = json.decode(response.body);
await stripe.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
applePay: true,
googlePay: true,
style: ThemeMode.dark,
testEnv: true,
merchantDisplayName: 'Flutter Stripe Store Demo',
customerId: paymentIntentData!['customer'],
paymentIntentClientSecret: paymentIntentData['client_secret'],
customerEphemeralKeySecret: paymentIntentData['ephemeralKey'],
));
//display payment sheet
await displayPaymentSheet();
if(isSuccessPaid){
logData(key, 'isSuccessPaid: $isSuccessPaid');
//handle result after payment successfully
}
and this is the display payment sheet function
try {
await stripe.presentPaymentSheet().then((value) {
isSuccessPaid = true;
}).onError((error, stackTrace){
GetIt.I<AppSnackBar>().show(error.toString());
logData(key,error.toString());
});
} catch (e) {
GetIt.I<AppSnackBar>().show(e.toString());
logData(key, '$e');
}
The problem is Android simulator works perfectly like this
but the IOS simulator can't display it and the terminal shows the errors like this
I don't know this is the platform error or just the simulator problem.Anyone got problem like this?Please help.Thanks!
Update Thursday 14 Apr 2022
For someone got same problem like me , i just want to share basic answer like this:
await stripe.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
applePay: true,
googlePay: true,
testEnv: true,
merchantCountryCode: 'US',
merchantDisplayName: 'Prospects',
customerId: paymentIntentData!['customer'] ?? 'Customer',
paymentIntentClientSecret: paymentIntentData!['client_secret'],
));
customerId and paymentIntentClientSecret mustn't be null so check null safety carefully and the response data must has the client_secret field

Can't re-log (autorelog) user to Nativescript Firebase App on iOS

I'm having problems re-logging the user previously logged in with Facebook or Google Sign In on my Nativescript iOS App. It works good with an email/password re-authentication on iOS.
It seems that the function
firebase.init({
persist:true,
onAuthStateChanged: (data: any) => {
console.log(JSON.stringify(data))
if (data.loggedIn) {
AuthService.tokenUid = data.user.uid;
// this.routerExtensions.navigate(["/splash"])
}
else {
AuthService.tokenUid = ''
}
},
iOSEmulatorFlush: true
}).then(
() => {
console.log("firebase.init done");
},
error => {
console.log(`firebase.init error: ${error}`);
}
);
return {"loggedIn":false,"user":null} when the user re-launch the app after closing it. It seems that the plugin nativescript/firebase (EddyVerbruggen
/
nativescript-plugin-firebase) might have a problem with the authentication on iOS. There is no problem with Android.

Image Classification in Nativescript via API

I will be building an app to detect cat diseases (in their eyes) using Nativescript-Vue.
I'm searching other image classifications project and plugins in Native Script but there where little to no results. I explored google vision, Microsoft custom vision, clarify, but there were no plugins ready for Native Script.
I'm not so good yet to convert react native implementation and its possible counterpart to Native Script. Has anyone tried it?
You may use the MLKit from Firebase plugin which is recommended by Google for mobile apps. Google Vision also has REST apis if you like to stick with that.
If you want to try it but given your credit card, you may use Google Vision, Amazon Rekognition, Microsofts and other ML related in the market. But if you dont want or have a credit card number, in my case, I use https://clarifai.com/ .
For the API package,npm install --save clarifai and for the implementation, I got it with,
const Clarifai = require('clarifai')
const app = new Clarifai.App({
apiKey: 'dac044d841bb40f6bc6a79e5d1a65fcf'
})
sendToClarifai(encoded_image) {
let vm = this
app.models.predict(Clarifai.GENERAL_MODEL, { base64: encoded_image }).then(
function (response) {
// do something with response
var concepts = response['outputs'][0]['data']['concepts']
console.log('CONCEPTS', concepts)
vm.isLoading = false
let isDetectedEyeRelated = false
//loop through items
concepts.forEach(obj => {
if (['disease', 'animal', 'pet', 'cat', 'cataract', 'cataracts', 'eye', 'conjunctivitis'].includes(obj.name)) {
isDetectedEyeRelated = true
}
//more to improve here but very inaccurate
})
//show message
let message = ""
let firstQuestionArray = []
if (isDetectedEyeRelated) {
message = "Your cat might have some eye problems."
firstQuestionArray = ["Do you see redness or discharge?", "Does your cat squinting or the emergence of the third eyelid?"]
} else {
message = "Our classification model cannot identify the subject.\nCheck camera settings and proper position."
firstQuestionArray = ["Does your cat has bright, clear evenly focused eyes?", "Do you see redness or discharge?", "Does your cat squinting or the emergence of the third eyelid?"]
}
//follow up questions
action({
message: message + '\n\nBelow are follow up questions:',
cancelButtonText: "Cancel",
actions: firstQuestionArray,
cancelable: false
})
.then(result => {
if (result.includes("redness") || result.includes("emergence")) { //A
action({
message: "Please select any of these symptoms to know what seems could be the problem",
cancelButtonText: "Cancel",
actions: ["Do you see any familiar pink or reddish color, sticky eye discharge and swelling?", "Did you notice any cloudiness in their eyes, change of iris color and unusual meowing?"],
cancelable: false
})
.then(result => {
if (result.includes("reddish")) { //A
alert({
title: "Identify",
message: "This could be a sign that your cat has conjunctivitis.",
okButtonText: "See Early Treatment"
}).then(() => {
vm.setTreatmentType('eye_conjunctivitis')
vm.setTreatmentTitle('Eye Conjunctivitis Identification and Treatment')
vm.$router.replace({
path: '/pdf-treatment'
})
})
} else if (result.includes("cloudiness")) { //b
alert({
title: "Identify",
message: "This could be a sign that your cat has cataract.",
okButtonText: "See Early Treatment"
}).then(() => {
vm.setTreatmentType('eye_cataract')
vm.setTreatmentTitle('Eye Cataract Identification and Treatment')
vm.$router.replace({
path: '/pdf-treatment'
})
})
}
})
} else if (result.includes("bright")) { //b
const user_data = LS.getItem(vm.loggedUsername)
const obj = JSON.parse(user_data)
obj.progress.eye = 'good condition'
//update the user data
LS.removeItem(vm.loggedUsername)
LS.setItem(vm.loggedUsername, JSON.stringify(obj))
alert({
title: "Congratulations",
message: "Your cat's eye is in good condition.",
okButtonText: "Done"
}).then(() => {
console.log("Alert dialog closed");
})
vm.$router.push({
path: '/categories'
})
}
})
},
function (err) {
// there was an error
console.log('CLARIFAI ERROR', err)
}
)
Or something similar with my implementation.

Nativescript | Firebase notification not working

I'm having a problem using firebase in my Nativescript application, when I'm using android its working great but not working with IOS. the problem is on message sending.
I'm using the push-plugin in the client side
This is the register part in the IOS client side using pushPlugin
const iosSettings:any = {
badge: true,
sound: true,
alert: true,
interactiveSettings: {
actions: [{
identifier: 'READ_IDENTIFIER',
title: 'Read',
activationMode: "foreground",
destructive: false,
authenticationRequired: true
}, {
identifier: 'CANCEL_IDENTIFIER',
title: 'Cancel',
activationMode: "foreground",
destructive: true,
authenticationRequired: true
}],
categories: [{
identifier: 'READ_CATEGORY',
actionsForDefaultContext: ['READ_IDENTIFIER', 'CANCEL_IDENTIFIER'],
actionsForMinimalContext: ['READ_IDENTIFIER', 'CANCEL_IDENTIFIER']
}]
},
notificationCallbackIOS: (message: any) => {
alert(JSON.stringify(message));
}
};
pushPlugin.register(iosSettings, (token: string) => {
// update the token in the server
alert("Device registered. Access token: " + token);
});
}
}, (errorMessage: any) => {
alert("Device NOT registered! " + JSON.stringify(errorMessage));
});
This is how i receive my token to the push notification,
after a got the token when i'm using the pusher application everything works great, i'm getting the notification in the IOS device
but the problem is when im trying to send the notification from the server!.
I get this error :
Invalid registration token provided. Make sure it matches the
registration token the client app receives from registering with FCM.
Node code in my server
var payload = {
data: {
targetId:userToken,
body: "some text"
}
};
var options = {
priority: "high",
contentAvailable: true,
timeToLive: 60 * 60 * 24
};
Admin.messaging().sendToDevice(userToken, <any>payload,options)
.then((response) => {
console.log('notification arrived successfully', response.results[0]);
})
.catch((error) => {
console.log('notification failed', error);
});
registration token for ios is not the same for android. I encountered the same wall you've encountered. You need to use https://github.com/node-apn/node-apn for IOS push notification. and firebase for android notification. You can do the logic on your backend by saving the token. with a field called type which is ios or android if ios you use node-apn and if android use sendToDevice provided by firebase.
Thats what i'm currently using with my current nativescript projects' I'm working on that involves push notification. Hope that helps you, mate.

Resources