فهرست منبع

#16 When link to the site with app is opened, then in app homepage is opened instead of particular link

Alex Trofimov 5 سال پیش
والد
کامیت
d83fdba37f
1فایلهای تغییر یافته به همراه6 افزوده شده و 29 حذف شده
  1. 6 29
      App.js

+ 6 - 29
App.js

@@ -399,42 +399,19 @@ export default class App extends Component<Props> {
 
         OneSignal.setLogLevel(6, 0);
         OneSignal.setAppId(ONESIGNALAPPID);
-        // OneSignal.inFocusDisplaying(0);
         OneSignal.promptForPushNotificationsWithUserResponse(response => {
             console.log("OneSignal Prompt response:", response);
         });
         OneSignal.setNotificationWillShowInForegroundHandler(notificationReceivedEvent => {
-            console.log("OneSignal: notification will show in foreground:", notificationReceivedEvent);
-            let notification = notificationReceivedEvent.getNotification();
-            console.log("OneSignal notification: ", notification);
-            const data = notification.additionalData;
-            console.log("OneSignal additionalData: ", data);
-            const button1 = {
-                text: "Cancel",
-                onPress: () => { 
-                    notificationReceivedEvent.complete(); 
-                },
-                style: "cancel"
-            };
-            const button2 = { 
-                text: "Complete", 
-                onPress: () => { 
-                    notificationReceivedEvent.complete(notification); 
-                }
-            };
-            Alert.alert("Complete notification?", "Test", [button1, button2], { 
-                cancelable: true 
-            });
+            console.log("OneSignal: notification in foreground:", notificationReceivedEvent);
         });
 
-        OneSignal.setNotificationOpenedHandler(notification => {
-
-            // TODO:
-            // if ('undefined' !== typeof(openResult.notification.payload.additionalData) && 'undefined' !== typeof(openResult.notification.payload.additionalData.url) && !openResult.notification.isAppInFocus) {
-            //     this.injectJavaScript(`window.location = '${openResult.notification.payload.additionalData.url}';`);
-            // }
+        OneSignal.setNotificationOpenedHandler(openResult => {
+            console.log("OneSignal: notification opened:", openResult);
 
-            console.log("OneSignal: notification opened:", notification);
+            if ('undefined' !== typeof(openResult.notification.additionalData) && 'undefined' !== typeof(openResult.notification.additionalData.url)) {
+                this.injectJavaScript(`window.location = '${openResult.notification.additionalData.url}';`);
+            }            
         });
 
         const deviceState = await OneSignal.getDeviceState();