Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Com 2115 #363

Merged
merged 5 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
"checkAutomatically": "ON_LOAD",
"fallbackToCacheTimeout": 3000
},
"notification": {
"icon": "./assets/images/android_notification_icon.png",
"color": "#005774"
},
"ios": {
"bundleIdentifier": "com.alenvi.compani",
"buildNumber": "1.11.0",
Expand Down
Binary file added assets/images/android_notification_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/AppContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ interface AppContainerProps {
statusBarVisible: boolean,
}

Notifications.addNotificationResponseReceivedListener(handleNotificationResponse);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ cette méthode créée-t-elle une possibilité de fuite mémoire ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expo aurait proposer quelque chose dans sa doc pour fermer le listener si c'était le cas non ?


const AppContainer = ({ setLoggedUser, statusBarVisible }: AppContainerProps) => {
const { tryLocalSignIn, alenviToken, appIsReady, signOut } = useContext(AuthContext);
const routeNameRef = useRef<string>();
Expand Down
8 changes: 5 additions & 3 deletions src/core/helpers/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,25 @@ import Users from '../../api/users';
import Courses from '../../api/courses';

export const registerForPushNotificationsAsync = async () => {
let finalStatus;

if (!Constants.isDevice) return { token: null, status: DENIED };

const { status: existingStatus } = await Notifications.getPermissionsAsync();
let finalStatus = existingStatus;
finalStatus = existingStatus;

if (existingStatus !== GRANTED) {
const { status } = await Notifications.requestPermissionsAsync();
finalStatus = status;
}

const token = (await Notifications.getExpoPushTokenAsync()).data;
const { data: token } = await Notifications.getExpoPushTokenAsync();
await asyncStorage.setExpoToken(token);

if (finalStatus !== GRANTED) return { token, status: DENIED };

if (Platform.OS === 'android') {
Notifications.setNotificationChannelAsync(
await Notifications.setNotificationChannelAsync(
'default',
{
name: 'default',
Expand Down