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

Platform not detected correctly on Android (Platform.OS) #30178

Closed
rgomezp opened this issue Oct 14, 2020 · 6 comments
Closed

Platform not detected correctly on Android (Platform.OS) #30178

rgomezp opened this issue Oct 14, 2020 · 6 comments
Labels
Needs: Triage 🔍 Platform: Android Android applications. Resolution: Locked This issue was locked by the bot.

Comments

@rgomezp
Copy link

rgomezp commented Oct 14, 2020

Description

The issue is simple, Platform is not detecting Android correctly in some instances. I am only ever able to reproduce the issue when I save my App.js file and React Native reloads the app. This is causing the OneSignal SDK package that also uses Platform to fall into an iOS-only code path (here).

React Native version:

System:
    OS: macOS 10.15.5
    CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
    Memory: 87.29 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.18.0 - /usr/local/bin/node
    Yarn: 1.12.3 - /usr/local/bin/yarn
    npm: 6.14.4 - /usr/local/bin/npm
    Watchman: Not Found
  Managers:
    CocoaPods: 1.8.4 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.0, DriverKit 19.0, macOS 10.15, tvOS 14.0, watchOS 7.0
    Android SDK:
      API Levels: 24, 26, 27, 28, 29
      Build Tools: 26.0.2, 27.0.3, 28.0.3, 29.0.0, 29.0.2
      System Images: android-23 | Google APIs Intel x86 Atom, android-27 | Google Play Intel x86 Atom, android-28 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6626763
    Xcode: 12.0.1/12A7300 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_191 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.9.0 => 16.9.0 
    react-native: ^0.63.3 => 0.63.3 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

  1. Clone project
git clone https://github.com/OneSignal/react-native-onesignal.git
cd react-native-onesignal/examples/RNOneSignal
git checkout react-native-issue-repro
yarn install
  1. Open the android directory with Android Studio and fix any build issues like signing config keystore , gradle, etc...

  2. react-native run-android

  3. Send yourself a notification by tapping the button "Post a Notification"

  4. Open App.js, on line 401 try playing with the 3rd argument. Change the line to OneSignal.postNotification({en:"Testing this post"}, {data:"data"}, state.userId); (i.e. remove the brackets from the last argument).

Somehow I can consistently reproduce the issue by doing that (send notif, remove brackets, save).

Expected Results

I expect the log not to print that the platform is iOS, since I am running this on Android.

Snack, code example, screenshot, or link to a repository:

See line 394 in App.js from the repository.

import { Platform } from 'react-native';
if (Platform.OS === 'ios') console.log("Platform is iOS");
SCREENSHOTS Screen Shot 2020-10-14 at 5 43 33 PM

Screenshot_20201014-174603_RNOneSignal

@Svarto
Copy link

Svarto commented Nov 8, 2020

similar problem, but my Platform.OS resolves to "false". This breaks linkages to native components and crashes the app. e.g.

Invariant Violation: requireNativeComponent: "RCTSwitch" was not found in the UIManager.

Any idea how to fix this?

@georgeMorales
Copy link

I have a similar problem, Platform.OS does not work well, sometimes it returns the correct value but other times it always returns false.
This all started when I upgraded react navigation from v4 to v5. With react navigation v4 I didn't have this problem.
Expo sdk 39
"@react-navigation/material-top-tabs": "^ 5.3.7",
"@react-navigation/native": "^ 5.8.7",
"@react-navigation / stack": "^ 5.12.4",

@rgomezp
Copy link
Author

rgomezp commented Dec 12, 2020

Updating this issue, I recently managed to reproduce it again in a different way. This time, it has nothing to do with saving any file and the metro bundler rebundling the app. It still thinks the value is ios.

Alternative reproduction steps:
1.

git clone https://github.com/OneSignal/react-native-onesignal.git
cd react-native-onesignal/examples/
git checkout ts_example_app
cd RNOneSignalTS
yarn install
react-native run-android
  1. Tap the "SUBSCRIBE" button
  2. Tap the "POST NOTIFICATION" button
  3. Tap the "CLEAR ONESIGNAL NOTIFICATIONS" button
DEVICE SCREENSHOT

Screen Shot 2020-12-12 at 3 13 33 PM


You will see that it thinks the platform is iOS. In the console, see that it prints:

"clearOneSignalNotifications: this function is not supported on iOS"

A message coming from this line in the OneSignal library...

static clearOneSignalNotifications() {
        if (!checkIfInitialized(RNOneSignal)) return;

        if (Platform.OS === 'android') {
            RNOneSignal.clearOneSignalNotifications();
        } else {
            console.log("clearOneSignalNotifications: this function is not supported on iOS");
        }
    }

and to be clear, Platform.OS is not null or undefined in this case. I printed the value of Platform.OS and it is ios.

@Svarto
Copy link

Svarto commented Dec 12, 2020

Just an update from my side, this was my user error. I found an instance in my app where I had accidentally tried to assign Platform.OS a value (I.e. Platform.OS = "ios"). This broke the Platform module and it never recovered until a restart.

@rgomezp
Copy link
Author

rgomezp commented Dec 17, 2020

An update, I had the exact same issue as @Svarto .
Looks like this is a non-issue.

@rgomezp rgomezp closed this as completed Dec 17, 2020
@miuel
Copy link

miuel commented Dec 23, 2020

Just an update from my side, this was my user error. I found an instance in my app where I had accidentally tried to assign Platform.OS a value (I.e. Platform.OS = "ios"). This broke the Platform module and it never recovered until a restart.

I had this silly error, I just fixed the error and work for me, thanks!

@facebook facebook locked as resolved and limited conversation to collaborators Dec 17, 2021
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Dec 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs: Triage 🔍 Platform: Android Android applications. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

5 participants