I'm newbie using the React Native environment and I'm facing some difficulties to understand what is happening to my app when I test the debug-app.apk without any development server.
I mean, currently, the problems are: send the userId of Onesignal API to my API, the oneSignal is not catching my device too, and upload files using AXIOS, and that problems don't exist when I run my app in an emulator.
Does anyone know why?
No matter how much I try to reload the app, my API is sending status:400 when the OneSignal is trying to connect to my device, but when I do this in emulator, having access to the metro server, the API sends status 400 to the first try, for some reason I don't know the OneSignal is not catching userId in the first try, but, in other attempts, the API is sending status:200, and OneSignal works well. Moreover, no matter what, the axios when I'm in development server is uploading the files very well while outside it doesn't even call the API.
My axios API connection and the code to upload files:
import axios from 'axios'
var URL = {
http: '<MY API>',
}
if (process.env.NODE_ENV !== 'dev') {
URL = {
http: '<MY API>',
}
}
export const api = axios.create({
baseURL: URL.http,
})
console.log(JSON.stringify(api))
import { token } from '../../graphql/storage'
import { api } from '../../services/api'
export type ImageUploadProps = {
uri: string
type: string
name: string
}
interface Props {
uploadImages: ImageUploadProps
}
export const upload = async ({ uploadImages }: Props) => {
const clientToken = await token()
const data = new FormData()
data.append('file', uploadImages)
// uploadImages.forEach(item => data.append('files', item))
try {
const res = await api.post('/upload', data, {
headers: {
'Content-Type': 'multipart/form-data',
authorization: `Bearer ${clientToken}`,
},
})
return res.data
} catch (e) {
console.log('UploadErro:', JSON.stringify(e))
}
}
My OneSignal initialization:
const initOneSignal = async () => {
OneSignal.setAppId('<MY APPID>')
OneSignal.setLogLevel(6, 0)
OneSignal.setRequiresUserPrivacyConsent(false)
OneSignal.promptForPushNotificationsWithUserResponse()
return OneSignal
}
const onesignal = await initOneSignal()
const data = await onesignal.getDeviceState()
if (data) {
try {
await setNotificationId({
variables: {
input: {
client_id,
notificationId: data!.userId,
},
},
})
} catch (e: any) {
console.log(JSON.stringify(e)) //erro aqui
}
}
I really don't know why this is happening, for some reason I thought that my device is not connecting to the API but, my app has a real time chat that works really well and other features that access the API is working well too.
I already found the solution guys, I just released the production version with
gradlew assembleRelease, that make works well