File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
packages/expo/src/modules/push Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -188,6 +188,23 @@ const InternalKnockExpoPushNotificationProvider: React.FC<
188188 [ knockClient ] ,
189189 ) ;
190190
191+ useEffect ( ( ) => {
192+ const fetchExpoTokenIfNeeded = async ( ) => {
193+ const { status : existingStatus } =
194+ await Notifications . getPermissionsAsync ( ) ;
195+ if ( existingStatus === "granted" && Device . isDevice ) {
196+ try {
197+ const token = await getExpoPushToken ( ) ;
198+ setExpoPushToken ( token ? token . data : null ) ;
199+ } catch ( error ) {
200+ console . error ( `[Knock] Error getting expo push token:` , error ) ;
201+ }
202+ }
203+ } ;
204+
205+ fetchExpoTokenIfNeeded ( ) ;
206+ } , [ ] ) ;
207+
191208 useEffect ( ( ) => {
192209 Notifications . setNotificationHandler ( {
193210 handleNotification :
You can’t perform that action at this time.
0 commit comments