Skip to content

Commit

Permalink
asdf
Browse files Browse the repository at this point in the history
  • Loading branch information
duogenesis committed Mar 10, 2024
1 parent a2b5a9e commit 049245b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 11 deletions.
7 changes: 5 additions & 2 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const App = () => {
const navigationContainerRef = useRef<any>();
const { height, width } = useWindowDimensions();

// useNotificationTest(); // TODO
useNotificationTest(); // TODO

const loadFonts = useCallback(async () => {
await Font.loadAsync({
Expand Down Expand Up @@ -326,7 +326,10 @@ const App = () => {
return (
<>
{!isLoading &&
<View style={{ height, width }}>
<View style={{
height: height,
width: width,
}}>
<NavigationContainer
ref={navigationContainerRef}
onStateChange={pushBrowserState}
Expand Down
3 changes: 2 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#ffffff"
}
},
"googleServicesFile": "./google-services.json"
},
"androidNavigationBar": {
"barStyle": "dark-content",
Expand Down
29 changes: 29 additions & 0 deletions google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"project_info": {
"project_number": "443037492722",
"project_id": "duolicious",
"storage_bucket": "duolicious.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:443037492722:android:4a2891159116ca1c5ab76b",
"android_client_info": {
"package_name": "app.duolicious"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyCc2FCgy-SIF1K07MOhkPqC7VAeSeOQsK0"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}
25 changes: 17 additions & 8 deletions notifications/notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async function sendPushNotification(expoPushToken) {
data: { someData: 'goes here' },
};

await fetch('https://exp.host/--/api/v2/push/send', {
const response = await fetch('https://exp.host/--/api/v2/push/send', {
method: 'POST',
headers: {
Accept: 'application/json',
Expand All @@ -33,9 +33,11 @@ async function sendPushNotification(expoPushToken) {
},
body: JSON.stringify(message),
});

console.log('sendPushNotification response', response);
}

async function registerForPushNotificationsAsync() {
async function registerForPushNotificationsAsync(): Promise<string | undefined> {
let token;

if (Platform.OS === 'android') {
Expand All @@ -58,10 +60,13 @@ async function registerForPushNotificationsAsync() {
alert('Failed to get push token for push notification!');
return;
}
token = await Notifications.getExpoPushTokenAsync({
projectId: Constants.expoConfig?.extra?.eas.projectId,
});
console.log(token);
const projectId = Constants.expoConfig?.extra?.eas.projectId;
console.log(projectId);
token = await Notifications.getExpoPushTokenAsync({ projectId });
console.log('expo token', token);

const deviceToken = await Notifications.getDevicePushTokenAsync();
console.log('device token', deviceToken);
} else {
alert('Must use physical device for Push Notifications');
}
Expand All @@ -70,11 +75,15 @@ async function registerForPushNotificationsAsync() {
}

const useNotificationTest = () => {
const [expoPushToken, setExpoPushToken] = useState('');
const [expoPushToken, setExpoPushToken] = useState<string | undefined>();
const notificationListener = useRef<Notifications.Subscription>();

useEffect(() => {
registerForPushNotificationsAsync().then(token => setExpoPushToken(token));
registerForPushNotificationsAsync()
.then(token => {
setExpoPushToken(token);
sendPushNotification(expoPushToken);
});

notificationListener.current = Notifications.addNotificationReceivedListener(notification => {
console.log(notification);
Expand Down

0 comments on commit 049245b

Please sign in to comment.