react-native-device-info / react-native-device-info Goto Github PK
View Code? Open in Web Editor NEWDevice Information for React Native iOS and Android
License: MIT License
Device Information for React Native iOS and Android
License: MIT License
Hello,
Is there a way to integrate the connection info into this module?
I just upgraded my project to use the latest rc version of react-native and when I went to npm install
I got thrown an error by npm2. I found this GitHub issue which discusses how npm2 ignores rc versions when trying to reconcile peerDependencies. I was curious if you'd be open to removing the peerDependencies requirement of this project to avoid this error?
Followed the instructions for installing 0.9.4 and tried both automatic and manual install. But it will crash when I run the app on my iPhone with these messages =>
(will you help?)
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[10]'
*** First throw call stack:
(0x18246adb0 0x181acff80 0x18235377c 0x182353614 0x10058f45c 0x1004447c8 0x10045eb24 0x1004446a8 0x1004361e8 0x100cbda7c 0x100cbda3c 0x100cc34e4 0x182420d50 0x18241ebb8 0x182348c50 0x183c30088 0x187632088 0x100034f94 0x181ee68b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
Hello! Trying to use this library with react-native 0.14.2 but getting the following error.
2015-12-28 10:12:41.674 [error][tid:main][RCTBatchedBridge.m:436] Error while loading: Unable to resolve module react-native-device-info from /Users/tom/projects/blueprint-native/tabs/LoggedOutScreen.js: Invalid directory /Users/node_modules/react-native-device-info
It doesn't appear to be searching the correct paths? /Users/node_modules instead of the full project path. Is there something obvious I am missing?
I had this issue with some other modules when upgrading to 0.14.2 but I am not particularly sure how it got resolved
This is what I'm currently receiving from the iPhone SE sim:
Device Manufacturer Apple
Device Brand Apple
Device Model Simulator
Device ID x86_64
System Name iOS
System Version 10.0
var DeviceInfo = require('react-native-device-info');
console.log(DeviceInfo.getDeviceId());
Android 5.1
I'm currently having an issue where the same file is being added two times to the project (Xcode).
The issue is with the polyfills.js
file but it is adding React again. All the files added are already in the project added by npm
.
⋊> ~/D/P/QueueProject on master ⨯ react-native start 21:25:13
┌────────────────────────────────────────────────────────────────────────────┐
│ Running packager on port 8081. │
│ │
│ Keep this packager running while developing on any JS projects. Feel │
│ free to close this tab and run your own packager instance if you │
│ prefer. │
│ │
│ https://github.com/facebook/react-native │
│ │
└────────────────────────────────────────────────────────────────────────────┘
Looking for JS files in
/Users/joanbarros/Development/Projects/QueueProject
[10:21:11 PM] <START> Building Dependency Graph
[10:21:11 PM] <START> Crawling File System
[Hot Module Replacement] Server listening on /hot
React packager ready.
[10:21:12 PM] <END> Crawling File System (1152ms)
[10:21:12 PM] <START> Building in-memory fs for JavaScript
[10:21:12 PM] <END> Building in-memory fs for JavaScript (640ms)
[10:21:12 PM] <START> Building in-memory fs for Assets
[10:21:13 PM] <END> Building in-memory fs for Assets (365ms)
[10:21:13 PM] <START> Building Haste Map
[10:21:13 PM] <START> Building (deprecated) Asset Map
[10:21:13 PM] <END> Building (deprecated) Asset Map (68ms)
Failed to build DependencyGraph: Naming collision detected: /Users/joanbarros/Development/Projects/QueueProject/ios/Pods/React/packager/react-packager/src/DependencyResolver/polyfills/polyfills.js collides with /Users/joanbarros/Development/Projects/QueueProject/node_modules/react-native/packager/react-packager/src/Resolver/polyfills/polyfills.js
Error: Naming collision detected: /Users/joanbarros/Development/Projects/QueueProject/ios/Pods/React/packager/react-packager/src/DependencyResolver/polyfills/polyfills.js collides with /Users/joanbarros/Development/Projects/QueueProject/node_modules/react-native/packager/react-packager/src/Resolver/polyfills/polyfills.js
at HasteMap._updateHasteMap (HasteMap.js:132:13)
at HasteMap.js:103:28
at tryCallOne (/Users/joanbarros/Development/Projects/QueueProject/node_modules/promise/lib/core.js:37:12)
at /Users/joanbarros/Development/Projects/QueueProject/node_modules/promise/lib/core.js:123:15
at flush (/Users/joanbarros/Development/Projects/QueueProject/node_modules/asap/raw.js:50:29)
at _combinedTickCallback (node.js:370:9)
at process._tickCallback (node.js:401:11)
How about a method to return app and build versions?
Use case, before sharing with an app, for example "Google Earth", check if app installed or desired version installed. If not, then developer prompt user with a store URL
// Check if Google Earth is installed
var gePackage = "com.google.earth";
bool geInstalled;
try
{
PackageManager.GetPackageInfo(gePackage, PackageInfoFlags.Activities);
geInstalled = true;
}
catch (PackageManager.NameNotFoundException)
{
geInstalled = false;
}
This is similar code to RNDeviceInfo/RNDeviceModule.java
try {
PackageInfo info = packageManager.getPackageInfo(packageName, 0);
constants.put("appVersion", info.versionName);
constants.put("buildNumber", info.versionCode);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
Is it possible to access these attributes from native code (Swift in my case) somehow? This is one of the few modules that it would be really helpful to make use of that info, instead of duplicating much of it. I understand this is a bit of an edge case and I'd be happy to make a PR if it's even a thing.
Works great in React, though!
Hi,
Mi name is Joan Barros. I'm currently trying to use this module in a project of mine and If no one else can do it then I guess I could maintain it.
Other candidates please comment on this issue with your proposal.
Regards.
While running:
console.log("App Version", DeviceInfo.getVersion());
I get this error:
Error TypeError: Cannot read property 'appVersion' of undefined
at Object.module.exports.getVersion (http://localhost:8081/index.android.bundle?platform=android&dev=true:57139:20)
at React.createClass.render (http://localhost:8081/index.android.bundle?platform=android&dev=true:1301:38)
at ReactCompositeComponentMixin._renderValidatedComponentWithoutOwnerOrContext (http://localhost:8081/index.android.bundle?platform=android&dev=true:13067:28)
at ReactCompositeComponentMixin._renderValidatedComponent (http://localhost:8081/index.android.bundle?platform=android&dev=true:13089:6)
at wrapper [as _renderValidatedComponent] (http://localhost:8081/index.android.bundle?platform=android&dev=true:3560:13)
at ReactCompositeComponentMixin._updateRenderedComponent (http://localhost:8081/index.android.bundle?platform=android&dev=true:13025:30)
at ReactCompositeComponentMixin._performComponentUpdate (http://localhost:8081/index.android.bundle?platform=android&dev=true:13006:6)
at ReactCompositeComponentMixin.updateComponent (http://localhost:8081/index.android.bundle?platform=android&dev=true:12916:6)
at wrapper [as updateComponent] (http://localhost:8081/index.android.bundle?platform=android&dev=true:3560:13)
at ReactCompositeComponentMixin.performUpdateIfNecessary (http://localhost:8081/index.android.bundle?platform=android&dev=true:12842:6)
Any help would be appreciated.
Thanks.
rn bug?
Test in ios
From what I understand the purpose is an ID that is specific to the install of an application.
async getInstanceID() {
// // Check for an existing ID
let id = await AsyncStorage.getItem("instance-id");
if (id != null) return id;
// Generate a new UUID
id = UUID();
// Save the ID
await AsyncStorage.setItem("instance-id", id);
return id;
}
That should do it across all platforms. Don't have time to make it look nice / work so I'm opening the issue.
After upgrading to 0.9.2
, I have this crash upon starting the app:
2016-04-15 17:22:54.850 MyApp.STAGING[6639:2558933] Loading JS bundle from file:///Users/dudeinthemirror/Library/Developer/CoreSimulator/Devices/DD3C4AE0-310F-4E3B-86F6-1AF87F33309F/data/Containers/Bundle/Application/D5E5316E-BAC7-4D92-9334-8B136FCA8327/MyApp.STAGING.app/main.jsbundle
2016-04-15 17:22:55.314 MyApp.STAGING[6639:2558933] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[11]'
*** First throw call stack:
(
0 CoreFoundation 0x0000000110d47d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000011078fdeb objc_exception_throw + 48
2 CoreFoundation 0x0000000110c4423e -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 318
3 CoreFoundation 0x0000000110c565bb +[NSDictionary dictionaryWithObjects:forKeys:count:] + 59
4 MyApp.STAGING 0x000000010b6362c3 -[RNDeviceInfo constantsToExport] + 924
5 MyApp.STAGING 0x000000010b5dfbad __32-[RCTModuleData gatherConstants]_block_invoke + 41
6 MyApp.STAGING 0x000000010b61d676 RCTExecuteOnMainThread + 53
7 MyApp.STAGING 0x000000010b5dfb74 -[RCTModuleData gatherConstants] + 156
8 libdispatch.dylib 0x000000011197dd9d
By changing package.json
from
"react-native-device-info": "^0.9.1",
to
"react-native-device-info": "0.9.1",
the crash goes away.
[[NSLocale currentLocale] objectForKey:NSLocaleCountryCode]
returns nil in some cases. This causes a crash when the dictionary is constructed in the constantsToExport
method.
In my case, I was running UI tests on the simulator.
This field should probably either be omitted or set to [NSNull null]
when the country code is nil.
Just some ideas I want to jot down for this package:
react-native-device
or rn-device
(see above)device.addEventListener("suspend", ...)
-- I have this in my current app and I'm looking to open source it (its not much) and all I can find is IOS only or Android only plugins; it's not a ton of code.import {systemVersion, instanceID, model, userAgent} from "react-native-device";
Just some ideas. I can publish another package for the events if we think its out-of-scope here.
@GantMan ?
On Android gradles build process gives the following exception:
Unknown source file : UNEXPECTED TOP-LEVEL EXCEPTION:
Unknown source file : com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzpq;
Unknown source file : at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
Unknown source file : at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
Unknown source file : at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
Unknown source file : at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
Unknown source file : at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
Unknown source file : at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
Unknown source file : at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
Unknown source file : at com.android.dx.command.dexer.Main.run(Main.java:277)
Unknown source file : at com.android.dx.command.dexer.Main.main(Main.java:245)
Unknown source file : at com.android.dx.command.Main.main(Main.java:106)
When removing react-native-device-info-stuff from build.gradle, settings.gradle and MainActivity.java, everything works fine.
According to the installation instruction:
Add the libRNDeviceInfo.a from the deviceinfo project to your project's Build Phases ➜ Link Binary With Libraries
But, i can not find libRNDeviceInfo.a
file in my node_modules/react-native-device-info/
folder. Why? Do i miss something?
Thanks for your help.
Plugin is not working for me: showing error
timezone is not function. My package.json dependencies are following:
"dependencies": {
"react": "15.3.2",
"react-native": "0.34.1",
"react-native-device-info": "^0.9.5"
}
error: package com.learnium does not exist
import com.learnium.RNDeviceInfo;
^
Nice library. Does a bunch of things I could make use of, except the device ID (ie. iPhone2,1). I was thinking of just doing a PR for it myself if it's not something already in the works. I imagine doing it something like this - with only the raw ID, or human friendly name - either works ok for me. What do you think @rebeccahughes?
Was going to start another module but wanted to see there's interest in adding Facebook's Android year-class to this module.
I'm using the module: react-native-fcm which depends on com.google.firebase:firebase-core:9.+
This lead to lots of classes being included on the class path twice. And my assemble gradle task wouldn't run.
This fix worked for me, but i'm not sure if it's right in the general case.
Thanks,
I want my app to authenticate via unique device identifier so that as long as they're on the same device, they don't need to create an account.
I am open to other ways of accomplishing this, device ID just seemed the best - however the DeviceInfo.getUniqueID()
keeps changing on the same device.
/BluetoothAdapter( 3513): Bluetooth binder is null
W/System.err( 3513): java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.bluetooth.BluetoothAdapter.getName()' on a null object reference
W/System.err( 3513): at com.learnium.RNDeviceInfo.RNDeviceModule.getConstants(RNDeviceModule.java:75)
W/System.err( 3513): at com.facebook.react.bridge.BaseJavaModule.writeConstantsField(BaseJavaModule.java:452)
W/System.err( 3513): at com.facebook.react.bridge.NativeModuleRegistry.writeModuleDescriptions(NativeModuleRegistry.java:82)
W/System.err( 3513): at com.facebook.react.bridge.CatalystInstanceImpl.buildModulesConfigJSONProperty(CatalystInstanceImpl.java:358)
W/System.err( 3513): at com.facebook.react.bridge.CatalystInstanceImpl.initializeBridge(CatalystInstanceImpl.java:125)
W/System.err( 3513): at com.facebook.react.bridge.CatalystInstanceImpl.access$200(CatalystInstanceImpl.java:39)
W/System.err( 3513): at com.facebook.react.bridge.CatalystInstanceImpl$1.call(CatalystInstanceImpl.java:96)
W/System.err( 3513): at com.facebook.react.bridge.CatalystInstanceImpl$1.call(CatalystInstanceImpl.java:91)
W/System.err( 3513): at com.facebook.react.bridge.queue.MessageQueueThreadImpl$1.run(MessageQueueThreadImpl.java:73)
W/System.err( 3513): at android.os.Handler.handleCallback(Handler.java:739)
W/System.err( 3513): at android.os.Handler.dispatchMessage(Handler.java:95)
W/System.err( 3513): at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
W/System.err( 3513): at android.os.Looper.loop(Looper.java:135)
W/System.err( 3513): at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:197)
W/System.err( 3513): at java.lang.Thread.run(Thread.java:818)
C:\Users\Evgeny\Documents\programming\ReactChat\android\app\src\main\java\com\reactchat\MainApplication.java:7: error: package com.learnium.RNDeviceInfo does not exist import com.learnium.RNDeviceInfo.RNDeviceInfo; ^ C:\Users\Evgeny\Documents\programming\ReactChat\android\app\src\main\java\com\reactchat\MainApplication.java:27: error: cannot find symbol new RNDeviceInfo(), ^ symbol: class RNDeviceInfo 3 errors FAILED
A React-Native app I'm developing in IOS simulator, if I double home click and swipe close my app, then reopen it, getUniqueID() returns a brand new UUID.
Is this expected behaviour?
Is it just a quirk of the simulator / react environment?
Any way [[UIDevice currentDevice] name]
(i.e. Rebecca's iPhone, or Arno's iPad) could be added? Is there an Android equivalent to this?
Android simulator has no bluetooth, so the part where you sniff for it generates an exception which leads to getting absolutly no info.
I'm seeing this warning:
ld: warning: object file (/Users/nickpomfret/Library/Developer/Xcode/DerivedData/pomochat-cvkhcsdfxgmgokbegzcqhdxmcngh/Build/Products/Debug-iphonesimulator/libRNDeviceInfo.a(RNDeviceInfo.o)) was built for newer iOS version (8.0) than being linked (7.0)
Would it be possible to release it linking to version 7?
noticing this one method is broken. Reviewed the code and it looks like it might be related to #14. @Bhullnatik , any chance you can confirm that this?
The iOS Deployment Target on RNDeviceInfo.xcodeproj has been set to iOS 9.0, so I couldn't build it since my app targets 8.0. So I had to change it to 8.0 on the library project file. I tested it on the 8.1 device on the simulator and had no problems.
I am wondering if there is a potential problem lowering this?
From README I understand that uniqueId corresponds to IDFV on iOS, is it null on android?
Do I need instanceId library to make it work on iOS, otherwise is it going to be null?
It's the same on android. But not on ios.
rnpm install
installs package only on iOS.
The only I find to install it on Android is the manual installation.
i follow the advise ,but i can't get the com.learnium.RNDeviceInfo ,i don't know how to expand it
rnpm link > https://github.com/rnpm/rnpm
It causes issues with other libs when a 3rd-party library, like yours, pins its play-services
dependencies at a particular version.
eg:
Unknown source file : com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/iid/MessengerCompat$1;
Unknown source file : at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
Unknown source file : at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
Unknown source file : at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
Unknown source file : at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
Unknown source file : at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
Unknown source file : at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
Unknown source file : at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
Unknown source file : at com.android.dx.command.dexer.Main.run(Main.java:277)
Unknown source file : at com.android.dx.command.dexer.Main.main(Main.java:245)
Unknown source file : at com.android.dx.command.Main.main(Main.java:106)
You have
compile 'com.google.android.gms:play-services-gcm:8.3.0'
You need to change it to:
compile 'com.google.android.gms:play-services-gcm:+'
Hi,
Thanks for the module.
Would you consider removing the <uses-permission android:name="android.permission.BLUETOOTH"/>
from Manifest.xml
since it is optional?
Every time I do a release of my app I realize when I upload to Google Play that a permission has been added because it comes back when I run npm install
... So I have to manually edit the manifest and recompile the whole thing.
It's a minor nuisance but it's really easy to prevent.
We could add a descriptive error message when the permission is not granted for newcomers to be warned about this.
Thanks!
It looks like the getTimezone method was added the day after the last version number bump. (see "Merge pull request #83 from antoinerousseau/timezone-getter "). Could you bump the version number so that an npm install gets this method added?
Followed the setup instructions, but am not able to get it to build. Tested on:
Here's the log after running react-native run-android
:
/Users/martins/RNDeviceInfoTest/android/app/src/main/java/com/rndeviceinfotest/MainApplication.java:11: error: package com.learnium.RNDeviceInfo does not exist
import com.learnium.RNDeviceInfo.RNDeviceInfo;
^
/Users/martins/RNDeviceInfoTest/android/app/src/main/java/com/rndeviceinfotest/MainApplication.java:28: error: cannot find symbol
, new RNDeviceInfo()
^
symbol: class RNDeviceInfo
2 errors
:app:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Might be a dupe of #91
Hi,
First off thanks for your module!
I just noticed that your last version now gets the device locale which is great. I wrote a module to do it myself but would be happy to use yours.
My problem is that locale.toString()
is... weird on Android as it can return unpredictable results and even the correct result is different from the iOS one (en_US
vs en-US
). locale.toLanguageTag()
seems more robust but only available on API 21 (Lollipop), but using it with a good (enough) fallback seems the good solution to me.
In reference here is the code I'm using now:
private String getCurrentLanguage() {
Locale current = getReactApplicationContext().getResources().getConfiguration().locale;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return current.toLanguageTag();
} else {
StringBuilder builder = new StringBuilder();
builder.append(current.getLanguage());
if (current.getCountry() != null) {
builder.append("-");
builder.append(current.getCountry());
}
return builder.toString();
}
}
I would be happy to look into that and submit a PR.
If I add this module my app start to require unnecessary permissions.
I thought it was because the BLUETOOTH
permission but even after removing it the behaviour continues.
The only things that I need permission are:
this is what i have on my manifest:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
And this are the permissions:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.