Comments (36)
The goal was to recieve PlayerID from Onesignal on application launch.
So in App.js for me worked the following code:
let userID;
componentWillMount() {
OneSignal.init(ONESIGNAL_APP_ID, {
kOSSettingsKeyAutoPrompt: true,
});
OneSignal.getPermissionSubscriptionState( (status) => {
userID = status.userId;
alert(userID);
});
}
from react-native-onesignal.
Because you needed to know it. That's why. :P React Native development is the worst development.
from react-native-onesignal.
Just invoking OneSignal.configure()
was enough to have an event emitted on the listener 'ids'
.
E.g.:
componentWillMount() {
OneSignal.init("APP ID GOES HERE", {kOSSettingsKeyAutoPrompt : true});
OneSignal.addEventListener('received', this.onReceived);
OneSignal.addEventListener('opened', this.onOpened);
OneSignal.addEventListener('ids', this.onIds);
OneSignal.configure(); // <-- add this line
}
componentWillUnmount() {
OneSignal.removeEventListener('received', this.onReceived);
OneSignal.removeEventListener('opened', this.onOpened);
OneSignal.removeEventListener('ids', this.onIds);
}
onReceived(notification) {
console.log("Notification received: ", notification);
}
onOpened(openResult) {
console.log('Message: ', openResult.notification.payload.body);
console.log('Data: ', openResult.notification.payload.additionalData);
console.log('isActive: ', openResult.notification.isAppInFocus);
console.log('openResult: ', openResult);
}
onIds(device) {
console.log('Device info: ', device);
}
from react-native-onesignal.
Good idea.
You now have:
OneSignal.idsAvailable((idsAvailable) => {
console.log(idsAvailable.playerId);
console.log(idsAvailable.pushToken);
});
on the latest package.
from react-native-onesignal.
@alejandrorbradford and anyone else getting here after a google search here it is for Swift:
OneSignal.idsAvailable { (pushID, pushToken) in
print(pushID)
print(pushToken)
}
from react-native-onesignal.
Yeah but that new onIds function never gets fired.
from react-native-onesignal.
So, using the latest version (3.2.2)
componentWillMount() {
OneSignal.init(Config().pushId, {kOSSettingsKeyAutoPrompt: true});
OneSignal.addEventListener('ids', this.updatePushId.bind(this));
OneSignal.configure()
}
async updatePushId(device) {
postJSON(UPDATE_PUSHID_URL,
{
user_id: this.props.user.id,
push_id: device.userId
},
{ 'Authorization': this.props.authentication_token }
);
};
This worked for me.
from react-native-onesignal.
This worked for me in functional component:
const data = await OneSignal.getDeviceState();
const player_id=data.userId;
from react-native-onesignal.
OneSignal.getDeviceState().then((idsAvailable) => {console.log('idsAvailable', idsAvailable?.userId)});
from react-native-onesignal.
I cannot get the playerId.
I tried with OneSignal.idsAvailable
but is not a function. Also tried with OneSignal.getUserId
and it display the error "is not a function".
How can I get the player id? I have installed the version 3.0.7.
Thanks in advance!
from react-native-onesignal.
@bhgames it worked. thanks.
OneSignal.configure() did the trick. why there is nothing about it in documents :|
from react-native-onesignal.
for people coming here in 2017:
Deprecations and Major Changes
March 21, 2017: Removed getRegistrationId() from documentation. getUserId() should always be used instead.
March 15, 2016: Deprecated getIdsAvailable() in favor of getUserId() and getRegistrationId(). Deprecated idsAvailableCallback in favor of subscriptionChange event.
from react-native-onesignal.
https://documentation.onesignal.com/docs/ios-native-sdk#section--getpermissionsubscriptionstate-
let userId = OneSignal.getPermissionSubscriptionState().subscriptionStatus.userId
print("your userID:",userId!)
from react-native-onesignal.
Has anyone figured this out? How can I get the Player ID of a specific device? I need this to be able to send push notifications to my users. Groups and filters are worthless in my application. The only thing I need is the Player ID and I can't find anything about how to get this in any of the documentation. Can someone please help? My app is built in Ionic V3.
from react-native-onesignal.
I have the same problem, documentatoin is not clear
import React from "react";
import { AsyncStorage } from "react-native";
import { createRootNavigator } from "./router";
import { isSignedIn } from "./auth";
import { YellowBox } from "react-native";
import OneSignal from "react-native-onesignal"; // Import package from node modules
//import { Provider } from 'react-redux';
//import { store } from '../app/redux/app-reducer';
YellowBox.ignoreWarnings([
"Warning: isMounted(...) is deprecated",
"Module RCTImageLoader"
]);
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
signedIn: false,
checkedSignIn: false
};
}
componentWillMount() {
OneSignal.init("my app id");
OneSignal.addEventListener("received", this.onReceived);
OneSignal.addEventListener("opened", this.onOpened);
OneSignal.addEventListener("ids", this.onIds);
}
componentWillUnmount() {
OneSignal.removeEventListener("received", this.onReceived);
OneSignal.removeEventListener("opened", this.onOpened);
OneSignal.removeEventListener("ids", this.onIds);
}
onReceived(notification) {
console.log("Notification received: ", notification);
}
onOpened(openResult) {
console.log("Message: ", openResult.notification.payload.body);
console.log("Data: ", openResult.notification.payload.additionalData);
console.log("isActive: ", openResult.notification.isAppInFocus);
console.log("openResult: ", openResult);
}
onIds(device) {
console.log("Device info: ", device);
}
componentDidMount() {
// status = AsyncStorage.getItem('loggedIn');
// if(status === 'success'){
// this.setState({checkedSignIn: true});
// }
isSignedIn()
.then(res => this.setState({ signedIn: res, checkedSignIn: true }))
.catch(err => alert("An error occurred"));
}
render() {
const { checkedSignIn, signedIn } = this.state;
// If we haven't checked AsyncStorage yet, don't render anything (better ways to do this)
if (!checkedSignIn) {
return null;
}
const Layout = createRootNavigator(signedIn);
return (
//<Provider store={store}>
<Layout />
// </Provider>
);
}
}
this is my code and it was told to me in other thread that i should use OneSignal.getPermissionSubscriptionState(callback) but where ? and how ? and how will I pass playerID? please someone help
from react-native-onesignal.
@davekedar I was able to get this to work by calling it in my ionViewDidLoad()
window["plugins"].OneSignal.getIds(function(ids) {
//alert(JSON.stringify(ids['userId']));
let playerID = ids['userId'];
//alert(playerID);
});
This is working for me; give it a shot.
from react-native-onesignal.
Thanks @kenef
from react-native-onesignal.
That's an awesome fast response! Thank you!
from react-native-onesignal.
Let me know if it works or you have any issues.
If not, i'll close this issue...
Thanks!
from react-native-onesignal.
@avishayil I looks like it's working on iOS. Thank you!
from react-native-onesignal.
Your'e welcome!
Closing issue.
from react-native-onesignal.
how does that work for iOS/Swift?
from react-native-onesignal.
Apparently it has now changed. According to the docs you have to add an event listener:
componentWillMount() {
OneSignal.addEventListener('ids', this.onIds);
}
componentWillUnmount() {
OneSignal.removeEventListener('ids', this.onIds);
}
onIds(device) {
console.log('Device info: ', device);
}
from react-native-onesignal.
What about Web push? Is it possible to "send notifications to an specific user"?
from react-native-onesignal.
@bhgames @jpmazza could you find a way to get current playerID?
from react-native-onesignal.
To help those still having issues getting the player_id
.
onIds(device) {
console.log('Device info: ', device);
}
The device
returns an object. So to really get the player_id
you're looking for, you should do something like device.userId
from react-native-onesignal.
How do I get this to work in Cordova?
from react-native-onesignal.
@luizmagao what is your environment?
from react-native-onesignal.
hello i have quickblox dialogid how i fetch quickblox userid by using this dialogid
from react-native-onesignal.
Just invoking
OneSignal.configure()
was enough to have an event emitted on the listener'ids'
.E.g.:
componentWillMount() { OneSignal.init("APP ID GOES HERE", {kOSSettingsKeyAutoPrompt : true}); OneSignal.addEventListener('received', this.onReceived); OneSignal.addEventListener('opened', this.onOpened); OneSignal.addEventListener('ids', this.onIds); OneSignal.configure(); // <-- add this line } componentWillUnmount() { OneSignal.removeEventListener('received', this.onReceived); OneSignal.removeEventListener('opened', this.onOpened); OneSignal.removeEventListener('ids', this.onIds); } onReceived(notification) { console.log("Notification received: ", notification); } onOpened(openResult) { console.log('Message: ', openResult.notification.payload.body); console.log('Data: ', openResult.notification.payload.additionalData); console.log('isActive: ', openResult.notification.isAppInFocus); console.log('openResult: ', openResult); } onIds(device) { console.log('Device info: ', device); }
So, How can you extract the ID ? Could you explain it more?
from react-native-onesignal.
Get the all playerid/userid using jquery and other .Please let me know it's possible or not
from react-native-onesignal.
This worked for me in functional component:
const data = await OneSignal.getDeviceState(); const player_id=data.userId;
thank you.. you are my hero
from react-native-onesignal.
OneSignal
can you send me the code you use here
from react-native-onesignal.
i cannot get playerid in latest version v9 of onesignal in react native
from react-native-onesignal.
OneSignal.getDeviceState().then(idsAvailable => {
console.log('idsAvailable', idsAvailable?.userId);
});
Throws an "undefined is not a function"
"react-native-onesignal": "^5.0.1",
from react-native-onesignal.
Hi @yepes,
OneSignal.getDeviceState()
is no longer available in the latest major release.
Please see this guide for all the methods and properties available in version 5.x.x of the react-native-onesignal library.
from react-native-onesignal.
Related Issues (20)
- [Bug]: Permission Not Granted (Android) HOT 5
- [Bug]: Push Notifications Not Reaching TestFlight Builds
- [Bug]: Crash "RuntimeException: Could not invoke OneSignal.hasNotificationPermission" HOT 1
- [Bug]: OneSignal.login() doesn't set the externalId in react native HOT 2
- [Bug]: Push Notification with status FAILED on iOS HOT 2
- Can't find any documentation on how to handle the actions buttons in my notification HOT 2
- ⚠️ 5.0.0 to 5.1.0 Deprecated - These version may be blocked or rate limited. Please update to 5.1.1 or newer ⚠️
- [Bug]: Android release APK crashing HOT 1
- [Bug]: External Id is not getting set HOT 1
- [Bug]: Cycle inside SampleProject; building could produce unreliable results HOT 1
- [Bug]: addTag could not be invoked HOT 2
- [Bug]: react native App Crashes in Android device Only, works on emulator HOT 1
- [Bug]: canRequestPermission is not working as expected HOT 3
- [Bug]: Missing API declaration HOT 3
- [Bug]: Can not build at AppCenter HOT 1
- [question]: Issue with Push Notifications in App Store Builds HOT 1
- iOS: Badge not showing HOT 1
- [Bug]: In v5, the Subscription Status does not change to 'Subscribed'. HOT 8
- [Bug]: permissionChange listener is not giving the correct hasPermission value until background/foreground HOT 1
- [question]: getIdAsync is returning null with latest SDK HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-onesignal.