Can not get SSID of iOS or Android device using NetInfo.
I am currently working on a mobile app that requires a specific SSID but I need to determine what the SSID is of the device.
iOS
Entitlements File
<key>com.apple.developer.networking.wifi-info</key>
<true/>
Info.plist
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Allow $(PRODUCT_NAME) to use your location</string>
<key>NSLocationUsageDescription</key>
<string>Allow $(PRODUCT_NAME) to use your location</string><key>NSLocationWhenInUseUsageDescription</key>
<string>Allow $(PRODUCT_NAME) to use your location</string>
Android
AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
React Native Code
I created a JavaScript file called NetworkInfo.js that has a function inside it to get the network state.
NetworkInfo.js
import React from 'react';
import NetInfo from "#react-native-community/netinfo";
export async function getNetworkState() {
NetInfo.configure({
shouldFetchWiFiSSID: true
});
let unsubscribe = NetInfo.addEventListener(state => {
console.log("Connection Type - ", state.type);
console.log("Is connected? - ", state.isConnected);
console.log("Details: - ", state.details.ssid ? state.details.ssid : "Error");
});
unsubscribe();
}
My App.tsx file after the Splash Screen loads calls the getNetworkState() above.
In the console log I receive
LOG Connection Type - wifi
LOG Is connected? - true
LOG Details: - Error
On the apple or android device I do not receive the popup asking to share location permissions.
Also, in the NetworkInfo.js the first state.details.ssid shows an "Unresolvable variable" error but the second one shows that it is part of the NetInfo API.
I have looked at various other issues but can not figure out anything that will help my specific issue.
I believe that all of the following have been met
"The SSID of the network. May not be present, null, or an empty string if it cannot be determined. On iOS, your app must meet at least one of the following requirements and you must set the shouldFetchWiFiSSID configuration option or no attempt will be made to fetch the SSID. On Android, you need to have the ACCESS_FINE_LOCATION permission in your AndroidManifest.xml and accepted by the user."
I am using
{
"#react-native-community/netinfo": "^9.3.7",
"react": "18.2.0",
"react-native": "0.71.0"
}
I appreciate any help to get beyond this issue.
Related
I have a java spring boot backend app, that I am trying to hook up to Firebase Cloud Messages.
I have an android app that uses firebase and I am trying to use this backend to push notifications.
I've generated a private key from firebase console project settings, placed the json file - and the following worked LOCALLY perfectly:
try {
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(new ClassPathResource("PATH_TO_GENERATED_JSON").
getInputStream())).build();
if (FirebaseApp.getApps().isEmpty()) {
FirebaseApp.initializeApp(options);
logger.info("Firebase application has been initialized");
}
} catch (IOException e) {
logger.error(e.getMessage());
}
...
response = FirebaseMessaging.getInstance().send(message);
I have set up google cloud build to automatically trigger and build from github.
But I cannot commit the json credentials file (right?), so for cloud deployment I have changed the initialization part to:
if (FirebaseApp.getApps().isEmpty()) {
FirebaseApp.initializeApp();
logger.info("Firebase application has been initialized");
}
But I have received errors information about project id not set, so I have also edited the cloud build trigger inline YAML with:
--update-env-vars=GOOGLE_CLOUD_PROJECT=XXXXXXXXXXX
But now I am getting the following error when trying to send the message:
com.google.firebase.messaging.FirebaseMessagingException: Permission 'cloudmessaging.messages.create' denied on resource '//cloudresourcemanager.googleapis.com/projects/XXXXXXXXXXX' (or it may not exist).
(XXXXXXXXXXX being my project id)
I've started giving "Firebase Cloud Messaging Admin" role left and right on https://console.cloud.google.com/iam-admin/iam?project= but that didn't help :(
Can anyone help?
Adding stack trace:
com.google.firebase.messaging.FirebaseMessagingException: Permission 'cloudmessaging.messages.create' denied on resource '//cloudresourcemanager.googleapis.com/projects/our-shield-329019' (or it may not exist).
at com.google.firebase.messaging.FirebaseMessagingException.withMessagingErrorCode(FirebaseMessagingException.java:51)
at com.google.firebase.messaging.FirebaseMessagingClientImpl$MessagingErrorHandler.createException(FirebaseMessagingClientImpl.java:293)
at com.google.firebase.messaging.FirebaseMessagingClientImpl$MessagingErrorHandler.createException(FirebaseMessagingClientImpl.java:282)
at com.google.firebase.internal.AbstractHttpErrorHandler.handleHttpResponseException(AbstractHttpErrorHandler.java:57)
at com.google.firebase.internal.ErrorHandlingHttpClient.send(ErrorHandlingHttpClient.java:108)
at com.google.firebase.internal.ErrorHandlingHttpClient.sendAndParse(ErrorHandlingHttpClient.java:72)
at com.google.firebase.messaging.FirebaseMessagingClientImpl.sendSingleRequest(FirebaseMessagingClientImpl.java:127)
at com.google.firebase.messaging.FirebaseMessagingClientImpl.send(FirebaseMessagingClientImpl.java:113)
at com.google.firebase.messaging.FirebaseMessaging$1.execute(FirebaseMessaging.java:137)
at com.google.firebase.messaging.FirebaseMessaging$1.execute(FirebaseMessaging.java:134)
at com.google.firebase.internal.CallableOperation.call(CallableOperation.java:36)
at com.google.firebase.messaging.FirebaseMessaging.send(FirebaseMessaging.java:104)
at com.google.firebase.messaging.FirebaseMessaging.send(FirebaseMessaging.java:86)
at com.miloszdobrowolski.investobotbackend.InvestobotAPIs.testNotification(InvestobotAPIs.java:120)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:655)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1726)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: com.google.api.client.http.HttpResponseException: 403 Forbidden
As listed in the Understanding Roles documentation, Firebase Cloud Messaging Admin does not have a cloudmessaging.messages.create permission. In order to add this permission, use one of the following roles:
Firebase Admin (roles/firebase.admin)
Firebase Grow Admin (roles/firebase.growthAdmin)
Firebase Admin SDK Administrator Service Agent (roles/firebase.sdkAdminServiceAgent)
Firebase SDK Provisioning Service Agent (roles/firebase.sdkProvisioningServiceAgent)
We would like to use a custom Chrome profile directory for our Cypress tests. The application we are testing uses a Web SQL database which needs to be loaded into the Chrome browser. We already tried this command which should be a valid chromium argument.
launchOptions.args.push('--user-data-dir=/Users/testuser/dev/chrome')
Our setup:
MacOs
Chrome v93
Cypress v8.3.0
Cypress Cucumber Preprocessor v4.1.0
The code we tried in our index.js (plugins folder):
const browserify = require('#cypress/browserify-preprocessor');
const cucumber = require('cypress-cucumber-preprocessor').default;
const resolve = require('resolve');
module.exports = (on, config) => {
const options = {
...browserify.defaultOptions,
typescript: resolve.sync('typescript', { baseDir: config.projectRoot }),
};
on('file:preprocessor', cucumber(options));
on('before:browser:launch', (browser = {}, launchOptions) => {
// `args` is an array of all the arguments that will
// be passed to browsers when it launches
console.log(launchOptions.args) // print all current args
launchOptions.args.push('--user-data-dir=/Users/testuser/dev/chrome')
launchOptions.args.push('--auto-open-devtools-for-tabs')
return launchOptions
})
};
This seems not to be working while the --auto-open-devtools-for-tabs command is working fine, but the custom profile is not loaded. Is this a known issue? Or can we debug to see what is happening?
update 24/9/2021
I see that the argument is passed to Chrome by Cypress, but Cypress overrides the Chrome profile path. Steps to reproduce:
Add launchOptions argument with --user-data-dir like mentioned above
Open Cypress dashboard (npx cypress open)
Run 1 test in Chrome
Chrome browser opens, type chrome://version/ in URL bar
--user-data-dir=/Users/testuser/dev/chrome is listed in the Command Line panel, but I also see --user-data-dir=/Users/xxxxx/Library/Application Support/Cypress/cy/production/browsers/chrome-stable/interactive listed, and that is the Profile Path which is being used by Cypress
According to this thread I understand that this is how Cypress works https://github.com/cypress-io/cypress/issues/3671
I have the following issue:
Trigger
An uncaught exception is being thrown and datadog logs SDK sends request to log the incident.
Expected outcome
One request is sent/incident and the incident is logged only once in Datadog UI.
Actual outcome
Datadog logs SDK sends many requests/incident (between 1k-2.5k) and the incident is logged many times in Datadog UI.
Additional Information
When disabling the Datadog RUM SDK, then the Datadog logs SDK behaves as expected. However, I want to run them both, so this is not an option at the moment.
I am using version 3.1.3 for both #datadog/browser-logs and #datadog/browser-rum packages.
Here's a screenshot to illustrate the issue:
Many requests being sent for one uncaught exception example
This is the code I am using to initialise both logs and RUM SDKs:
import { datadogLogs } from '#datadog/browser-logs';
import { datadogRum } from '#datadog/browser-rum';
if (process.env.NODE_ENV === 'production' && process.env.DATADOG_CLIENT_TOKEN) {
const environment = getEnvironment();
const config = {
site: 'datadoghq.eu',
clientToken: process.env.DATADOG_CLIENT_TOKEN,
service: typeof DATADOG_SERVICE !== 'undefined' ? DATADOG_SERVICE : undefined,
env: environment ? `${environment}` : undefined,
proxyHost: process.env.PROXY_HOST
};
datadogLogs.init(config);
if (process.env.DATADOG_APPLICATION_ID) {
datadogRum.init({
...config,
trackInteractions: true,
applicationId: process.env.DATADOG_APPLICATION_ID
});
datadogRum.setUser({
name: service.getName(),
email: service.getEmail()
});
}
}
I had the same issue, Upgrading both Datadog Rum and logging to 3.6.13 fixed this for me:
"#datadog/browser-logs": "^3.6.13",
"#datadog/browser-rum": "^3.6.13",
For anyone else:
Use localhost, not custom domain names. For some reason, DD_RUM.getInternalContext() didn't work for custom domain names.
Install versions of both RUM and logs - latest and possibly the same version. Incase you want specific varying versions, check the dependency packages for the datadog packages on the package.lock. It can be different which can throw errors.
I am trying to get ipyauth running inside a jupyter notebook as described here. However when clicking on the 'Sign In' button, no pop-up appears. Instead the callback runs into MIME type conflicts.
Two weeks ago, I have been able to run this demo notebook, but a (not related) problem forced me to reinstall ipyauth, and now I run into this issue. I have set up a new Anaconda3 environment and installed ipyauth as described in this tutorial. My jupyter notebook version is 5.7.6 and all necessary extensions are enabled, as listed in the dev-install section.
Opening a console shows the following error, after clicking on the 'Sign In' button:
Script from http://localhost:8888/callback/assets/util.js was blocked due to mime type mismatch
In Firefox the console also states the conflict is due to "text/html". The lines given in the console before the MIME mismatch are:
btn_main clicked widget_box.js:84:20
start startAuthFlow widget_auth.js:38:4
name=google, isIframeMode=true widget_auth.js:46:4
paramsModel widget_util.js:4:4
{"name":"google","url_params":{"response_type":"token","client_id":"729266704353-i9eueh2db24if69v2ohj4brfa94c48ns.apps.googleusercontent.com","redirect_uri":"http://localhost:8888/callback/","scope":"profile openid","include_granted_scopes":"false"}} widget_util.js:5:4
paramsFull widget_util.js:4:4
{"name":"google","authorize_endpoint":"https://accounts.google.com/o/oauth2/v2/auth","url_params":{"response_type":"token","redirect_uri":"http://localhost:8888/callback/","client_id":"729266704353-i9eueh2db24if69v2ohj4brfa94c48ns.apps.googleusercontent.com","scope":"profile openid","access_type":"online","state":"google,iframe,fbixswbono","include_granted_scopes":"false","prompt":"none"},"scope_separator":" ","isJWT":false} widget_util.js:5:4
authUrl widget_util.js:4:4
"https://accounts.google.com/o/oauth2/v2/auth?response_type=token&redirect_uri=http%3A%2F%2Flocalhost%3A8888%2Fcallback%2F&client_id=729266704353-i9eueh2db24if69v2ohj4brfa94c48ns.apps.googleusercontent.com&scope=profile%20openid&access_type=online&state=google%2Ciframe%2Cfbixswbono&include_granted_scopes=false&prompt=none" widget_util.js:5:4
start buidReadMessage widget_auth.js:80:4
----------- startAuthFlowInIframe widget_util.js:4:4
undefined widget_util.js:5:4
Other than that, the notebook does not react to the button click.
Do I have to change something in my jupyter config file? Can I somehow find out where this error is exactly coming from? Is this a bug in ipyauth, or am I doing something completely wrong?
In the current version of ipyauth (0.2.5), the Content-Type header of the assets/util.js and assets/main.js files are not set.
A fix for this is to follow the Dev Install section of the docs, installing all necessary extensions, but before you run jupyter notebook to open the notebook interface, change ipyauth/ipyauth/ipyauth_callback/server_extension.py to
import os
import mimetypes
from notebook.base.handlers import IPythonHandler
from notebook.utils import url_path_join
def load_jupyter_server_extension(nb_app):
web_app = nb_app.web_app
web_app.settings['jinja2_env'].loader.searchpath += [
os.path.join(os.path.dirname(__file__), 'templates'),
os.path.join(os.path.dirname(__file__), 'templates', 'assets'),
]
class CallbackHandler(IPythonHandler):
"""
"""
def get(self, path):
"""
"""
nb_app.log.info("in CallbackHandler with path={}".format(path))
self.write(self.render_template('index.html'))
class CallbackAssetsHandler(IPythonHandler):
"""
"""
def get(self, path):
"""
"""
nb_app.log.info("in CallbackAssetsHandler with path={}".format(path))
mime_type, _ = mimetypes.guess_type(path)
self.set_header('Content-Type', mime_type)
self.write(self.render_template(path))
host_pattern = '.*$'
base_url = web_app.settings['base_url']
web_app.add_handlers(
host_pattern,
[(url_path_join(base_url, '/callback/assets/(.*)'), CallbackAssetsHandler),
(url_path_join(base_url, '/assets/(.*)'), CallbackAssetsHandler),
(url_path_join(base_url, '/callback(.*)'), CallbackHandler),
(url_path_join(base_url, '/callback.html(.*)'), CallbackHandler),
]
)
nb_app.log.info("ipyauth callback server extension enabled")
This adds the correct Content-Type to those two javascript files.
I'll open an issue on the ipyauth repo regarding this problem. Hopefully a more robust solution will be added to the master branch soon so we can use this tool in production
I have been developing a web app (for a few months) that is built on top of CRA. Everything has been working as intended until this morning when I realized that the npm (or yarn) start script is no longer reusing the existing tab I have open in Chrome. It instead opens a new tab at localhost:3000 even if there are existing tabs at localhost:3000. I have been investigating this for a few hours but am yet to find a solution. I added a log statement in the CRA script (within my node modules) that handles the reusing of existing tabs upon startup of the app.
function startBrowserProcess(browser, url) {
// If we're on OS X, the user hasn't specifically
// requested a different browser, we can try opening
// Chrome with AppleScript. This lets us reuse an
// existing tab when possible instead of creating a new one.
const shouldTryOpenChromeWithAppleScript =
process.platform === 'darwin' &&
(typeof browser !== 'string' || browser === OSX_CHROME);
if (shouldTryOpenChromeWithAppleScript) {
try {
// Try our best to reuse existing tab
// on OS X Google Chrome with AppleScript
execSync('ps cax | grep "Google Chrome"');
execSync('osascript openChrome.applescript "' + encodeURI(url) + '"', {
cwd: __dirname,
stdio: 'ignore',
});
return true;
} catch (err) {
console.log(err);
// Ignore errors.
}
}
This is the output of the log statement:
{ Error: Command failed: osascript openChrome.applescript "http://localhost:3000/"
at checkExecSyncError (child_process.js:621:11)
at execSync (child_process.js:658:13)
at startBrowserProcess (/Users/***/Desktop/WorkSpace/React/***/node_modules/react-dev-utils/openBrowser.js:78:7)
at openBrowser (/Users/***/Desktop/WorkSpace/React/***/node_modules/react-dev-utils/openBrowser.js:122:14)
at Server.devServer.listen.err (/Users/***/Desktop/WorkSpace/React/***/node_modules/react-scripts/scripts/start.js:100:7)
at Server.returnValue.listeningApp.listen (/Users/***/Desktop/WorkSpace/React/***/node_modules/webpack-dev-server/lib/Server.js:604:10)
at Object.onceWrapper (events.js:273:13)
at Server.emit (events.js:182:13)
at emitListeningNT (net.js:1328:10)
at process.internalTickCallback (internal/process/next_tick.js:72:19)
status: 1,
signal: null,
output: [ null, null, null ],
pid: 2691,
stdout: null,
stderr: null }
It seems to have an issue running the Applescript command that handles this but I am unsure why. One of the other developers that is working on the same app locally is not having this issue. One change I made recently was upgrading to the new macOS Mojave. But the other developer just upgraded as well and is not having this issue.
Does anyone know what could be wrong?
To avoid opening a new tab,
you'll need to create an .env file in the root of your project and add this line,
BROWSER=none.
As shown here
Turns out after I upgraded Mojave I denied interface access to Google Chrome from my terminal. So it was unable to run the "reuse" tab script.