OneSignal/onesignal-expo-plugin

[BUG] OneSignal notification does not appear on iOS, but it does on Android (In App message works perfectly on both)

szbphoto opened this issue · 5 comments

So I added onesignal-expo-plugin and react-native-onesignal to my project, I made everything what was wrote on the website After this i made a developmen-simulator build for my app I tested the app on IOS and on Android too, on android i get the notification instantly but on IOS i'm not.

So i checked the notification report on OneSignal dashboard and the ios fall into failed. I checked everything, I added everything what i had to, the p12 file is correct, I did everything multiple times before i write here, I haven't ejected my ios app because I want to keep expo managing my ios/android application well. What should I try to fix this issue?

Android works correctly but ios don't and I really need your help! The in-app message works correctly just the push notification don't

Versions:

 "react-native-onesignal": "^4.5.0",
    "onesignal-expo-plugin": "^1.3.0",

I don't want to eject my ios code and I saw too many articles and videos how others use it and works. Please help me whats wrong.

My code example what I tried just now:

const initialOnesignal = async () => {
  
   OneSignal.setAppId('HIDEN FOR NOW');


   OneSignal.promptForPushNotificationsWithUserResponse();

  
   OneSignal.setNotificationWillShowInForegroundHandler(
     notificationReceivedEvent => {
       console.log(
         'OneSignal: notification will show in foreground:',
         notificationReceivedEvent,
       );
       let notification = notificationReceivedEvent.getNotification();
       console.log('notification: ', notification);
       const data = notification.additionalData;
       console.log('additionalData: ', data);
      
       notificationReceivedEvent.complete(notification);
     },
   );

  
   OneSignal.setNotificationOpenedHandler(notification => {
     console.log('OneSignal: notification opened:', notification);
   });
 };

And I also tried this way:


useEffect(() => {
    OneSignal.setAppId('HIDEN FOR NOW');

    
    OneSignal.promptForPushNotificationsWithUserResponse(response => {
      console.log('Prompt response:', response);
    });

    
    OneSignal.setNotificationWillShowInForegroundHandler(
      notificationReceivedEvent => {
        console.log(
          'OneSignal: notification will show in foreground:',
          notificationReceivedEvent,
        );
        let notification = notificationReceivedEvent.getNotification();
        console.log('notification: ', notification);
        const data = notification.additionalData;
        console.log('additionalData: ', data);
        // Complete with null means don't show a notification.
        notificationReceivedEvent.complete(notification);
      },
    );

    
    OneSignal.setNotificationOpenedHandler(notification => {
      console.log('OneSignal: notification opened:', notification);
    });
  }, []);

Tried to only add my AppId as well. I guess i tried everyting.

I have tried to regenerate p12 file, try multiple code examples, run on simultaor and on device too. Tried to use useEffect and simple function as well.

how I installed the packages:

Tried to install onesignal-expo-plugin first and then react-native-onesignal and tried with the opposite.
I read all article, seen all youtube videos, all docummentation etc...

Hi @Agentisreal sorry you are having some issues getting push notifications to work on iOS. Note that until XCode 14/iOS 16, push notifications to the simulator was not supported. If you haven't met the criteria for this, ensure you use a real device.

There doesn't look to be anything incorrect with your sample code. When running on a real iOS device, can you provide the log that shows the time during the OneSignal initialization code you've written? Also, if there are any error messages in the OneSignal dashboard notification report, please provide those as well.

Thanks!
Brian

Hi @brismithers ,

I try to get push notifications on my real device, I would like to provide any logs for you from my real device but I don't know how to get log from my real device?

Thanks!

Agentisreal

@brismithers
So now I made a new build with the same code, now with
OneSignal.setLogLevel(6, 3)

In my OneSignal dashboard i can see inside the users that my phone is succesfully subscribed and external id set correctly.

So if any error is in my code etc will shown in an alert.

I tried to send a push notification again and it's failed with: Failed (Errored) (in my onesignal profile)
In my application there's no error or alert showed so i guess everything should work fine.

What should I do now? I tried to debug anything but I can't get a single error.

my package.json:

"dependencies": {
   "@react-native-async-storage/async-storage": "^1.17.11",
   "@react-native-community/masked-view": "^0.1.11",
   "@react-navigation/bottom-tabs": "^6.5.0",
   "@react-navigation/native": "^6.1.0",
   "@react-navigation/native-stack": "^6.9.5",
   "axios": "^1.2.1",
   "expo": "^47.0.8",
   "expo-apple-authentication": "~5.0.1",
   "expo-crypto": "~12.0.0",
   "expo-dev-client": "~2.0.1",
   "expo-device": "^5.0.0",
   "expo-google-sign-in": "^11.0.0",
   "expo-image-picker": "~14.0.2",
   "expo-linear-gradient": "^12.0.1",
   "expo-splash-screen": "~0.17.5",
   "expo-status-bar": "~1.4.2",
   "expo-updates": "~0.15.6",
   "firebase": "^9.15.0",
   "onesignal-expo-plugin": "1.3.0",
   "prop-types": "^15.8.1",
   "react": "18.1.0",
   "react-firebase-hooks": "^5.1.1",
   "react-native": "0.70.5",
   "react-native-event-listeners": "^1.0.7",
   "react-native-gesture-handler": "^2.8.0",
   "react-native-onesignal": "^4.5.0",
   "react-native-reanimated": "^2.13.0",
   "react-native-safe-area-context": "^4.4.1",
   "react-native-screens": "^3.18.2",
   "react-native-svg": "13.4.0",
   "react-native-uuid-generator": "^6.1.1",
   "request": "^2.88.2",
   "uuid": "^9.0.0"
 },

my app.json:



    "ios": {
      "supportsTablet": true,
      "bundleIdentifier": "com.hidden.hidden",
      "usesAppleSignIn": true,
      "deploymentTarget": "12.0",
      "buildNumber": "3"
    },
    "extra": {
      "oneSignalAppId": "HIDDEN",
      "eas": {
        "build": {
          "experimental": {
            "ios": {
              "appExtensions": [
                {
                  "targetName": "OneSignalNotificationServiceExtension",
                  "bundleIdentifier": "com.hidden.hidden.OneSignalNotificationServiceExtension",
                  "entitlements": {
                    "com.apple.security.application-groups": [
                      "group.com.hidden.hidden.onesignal"
                    ]
                  }
                }
              ]
            }
          }
        },
        "projectId": "HIDDEN"
      }
    },

 "plugins": [
      [
        "onesignal-expo-plugin",
        {
          "mode": "development",
          "devTeam": "HIDDEN",
          "iPhoneDeploymentTarget": "12.0"
        }
      ],
      [
        "expo-image-picker",
        {
          "photosPermission": "The app accesses your photos to let you share them with your friends."
        }
      ],
      [
        "expo-apple-authentication"
      ]
    ],

SOLVED

How to solve this problem: Generate new certificates with expo, download it from expo.dev. Upload it to OneSignal and disable/enable OneSignal account

@Agentisreal I'm having the same issue.

disable/enable OneSignal account

What do you mean by this?