the main one is: we can’t expose the credentials to the expo client app in the app store because then anyone could send any message to any user of the client app. and we think its important to send push notifications in the client.
I think Expo is great as a pre-bundled set of native libraries that have been tested and validated together. Not having to worry about the native part of react-native makes the whole experience a lot better.
However, the end result should in my opinion still be a standalone build. There’s already an operational dependency on the Expo systems for the OTA updates and the dynamically loaded assets which I’m having a hard time turning off. Next to that, it’s impossible to send a push notification without using yet another Expo backend system. I understand the business case behind this strategy, but to me it’s a reason to eject as soon as the app has at least some users on it, and why Expo is probably not the right fit for large companies.
I will let my code using expo-server-sdk and firebase functions is necessary typscript
index.ts
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import { Expo, ExpoPushMessage } from 'expo-server-sdk';
// // Start writing Firebase Functions
// // https://firebase.google.com/docs/functions/typescript
//
// export const helloWorld = functions.https.onRequest((request, response) => {
// response.send("Hello from Firebase!");
// });
admin.initializeApp()
//let expo = new Expo();
export const prueba = functions.firestore.document('prueba/TY6SCYQwSEk1M7sPzWK4').onUpdate(()=>{
//const allTokens = [];
const messages: ExpoPushMessage[] = [];
const exp = new Expo()
for (const pushToken of ["ExponentPushToken[Yourcode]"]) {
// Each push token looks like ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]
// Check that all your push tokens appear to be valid Expo push tokens
if (!Expo.isExpoPushToken(pushToken)) {
console.error(`Push token ${pushToken} is not a valid Expo push token`);
continue;
}else{
console.log("funciono el atoken");
}
// Construct a message (see https://docs.expo.io/versions/latest/guides/push-notifications)
messages.push({
to: pushToken,
sound: 'default',
body: 'Dalvin Notificacion',
data: { withSome: 'data' },
})
}
const chunks = exp.chunkPushNotifications(messages);
// Send the chunks to the Expo push notification service. There are
// different strategies you could use. A simple one is to send one chunk at a
// time, which nicely spreads the load out over time:
for (const chunk of chunks) {
try {
const ticketChunk = exp.sendPushNotificationsAsync(chunk);
console.log(ticketChunk);
// NOTE: If a ticket contains an error code in ticket.details.error, you
// must handle it appropriately. The error codes are listed in the Expo
// documentation:
// https://docs.expo.io/versions/latest/guides/push-notifications#response-format
} catch (error) {
console.error(error);
}
}
});
Thanks for the reply,
I used your code. there is no error in the code. But it says in the function logs as “Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions”.