G

Re

public
Guest Apr 01, 2025 Never 25
Clone
Plaintext paste1.txt 70 lines (54 loc) | 2.27 KB
1
// En NotificationContext.tsx, 1-122 - Modificar el metodo responseListener.current
2
3
responseListener.current =
4
Notifications.addNotificationResponseReceivedListener((response) => {
5
console.log(
6
"🔔 Notification Response: ",
7
JSON.stringify(response, null, 2),
8
);
9
10
// Extraer los datos de la notificacion
11
const data = response.notification.request.content.data;
12
const url = data?.url;
13
14
if (url && typeof url === 'string') {
15
DeviceEventEmitter.emit('NotificationTapped', { url });
16
}
17
});
18
19
20
// En index.tsx agregar un useEffect
21
useEffect(() => {
22
const notificationTapListener = DeviceEventEmitter.addListener(
23
'NotificationTapped',
24
(data) => {
25
if (data.url) {
26
setUri(data.url);
27
if (webViewRef.current) {
28
webViewRef.current.reload();
29
}
30
}
31
}
32
);
33
34
return () => notificationTapListener.remove();
35
}, []);
36
37
38
// Para iOS, en ios/toqueApp/AppDelegate.mm
39
40
// Agregar despues del metodo messaging:didReceiveRegistrationToken:
41
42
// Manejo de notificaciones cuando la app esta en primer plano
43
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
44
willPresentNotification:(UNNotification *)notification
45
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
46
completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert);
47
}
48
49
// Manejo de notificaciones cuando el usuario interactua
50
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
51
didReceiveNotificationResponse:(UNNotificationResponse *)response
52
withCompletionHandler:(void (^)(void))completionHandler {
53
NSDictionary *userInfo = response.notification.request.content.userInfo;
54
55
// Pasar los datos de la notificacion
56
if (self.bridge) {
57
[NSNotificationCenter.defaultCenter postNotificationName:@"RemoteNotificationReceived" object:self userInfo:userInfo];
58
}
59
60
completionHandler();
61
}
62
63
64
En android/ revisar que MainActivity.java incluya:
65
66
@Override
67
public void onNewIntent(Intent intent) {
68
super.onNewIntent(intent);
69
setIntent(intent);
70
}