目前是否可以在 iOS 上像这样获取当前的 OneSignal 用户 ID/玩家 ID? https://documentation.onesignal.com/docs/ios-sdk-api#section -idsavailable。
我需要它向特定用户发送特定通知。
好主意。
您现在拥有:
OneSignal.idsAvailable((idsAvailable) => {
console.log(idsAvailable.playerId);
console.log(idsAvailable.pushToken);
});
在最新的包上。
这是一个了不起的快速反应! 谢谢!
让我知道它是否有效或您有任何问题。
如果没有,我将关闭此问题...
谢谢!
@avishayil我看起来它在 iOS 上运行。 谢谢!
别客气!
结题。
这对 iOS/Swift 是如何工作的?
@alejandrorbradford和其他任何人在谷歌搜索后到达这里是 Swift:
OneSignal.idsAvailable { (pushID, pushToken) in
print(pushID)
print(pushToken)
}
对于 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.
我无法获得 playerId。
我试过OneSignal.idsAvailable
但不是函数。 还尝试使用OneSignal.getUserId
并显示错误“不是函数”。
如何获取玩家ID? 我已经安装了 3.0.7 版本。
提前致谢!
显然它现在已经改变了。 根据文档,您必须添加一个事件侦听器:
````
componentWillMount() {
OneSignal.addEventListener('ids', this.onIds);
}
componentWillUnmount() {
OneSignal.removeEventListener('ids', this.onIds);
}
onIds(设备){
console.log('设备信息:', device);
}
````
是的,但新的 onIds 函数永远不会被触发。
网页推送呢? 是否可以“向特定用户发送通知”?
@bhgames @jpmazza你能找到获取当前玩家ID的方法吗?
所以,使用最新版本(3.2.2)
componentWillMount() {
OneSignal.init(Config().pushId, {kOSSettingsKeyAutoPrompt: true});
OneSignal.addEventListener('ids', this.updatePushId.bind(this));
OneSignal.configure()
}
异步 updatePushId(设备){
postJSON(UPDATE_PUSHID_URL,
{
user_id: this.props.user.id,
push_id: device.userId
},
{'授权':this.props.authentication_token }
);
};
这对我有用。
@bhgames它奏效了。 谢谢。
OneSignal.configure() 做到了。 为什么文档中没有关于它的内容:|
因为你需要知道它。 这就是为什么。 :P React Native 开发是最糟糕的开发。
https://documentation.onesignal.com/docs/ios-native-sdk#section --getpermissionsubscriptionstate-
let userId = OneSignal.getPermissionSubscriptionState().subscriptionStatus.userId
print("your userID:",userId!)
目标是在应用程序启动时从 Onesignal 接收 PlayerID。
所以在 App.js 中为我工作了以下代码:
let userID;
componentWillMount() {
OneSignal.init(ONESIGNAL_APP_ID, {
kOSSettingsKeyAutoPrompt: true,
});
OneSignal.getPermissionSubscriptionState( (status) => {
userID = status.userId;
alert(userID);
});
}
有没有人想过这个? 如何获取特定设备的玩家 ID? 我需要这个才能向我的用户发送推送通知。 组和过滤器在我的应用程序中毫无价值。 我唯一需要的是玩家 ID,我在任何文档中都找不到有关如何获取它的任何信息。 有人可以帮忙吗? 我的应用程序是用 Ionic V3 构建的。
我有同样的问题,文档不清楚
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>
);
}
}
这是我的代码,它在其他线程中告诉我我应该使用 OneSignal.getPermissionSubscriptionState(callback) 但是在哪里? 如何 ? 我将如何通过 playerID? 请有人帮忙
@davekedar我能够通过在我的 ionViewDidLoad() 中调用它来让它工作
window["plugins"].OneSignal.getIds(function(ids) {
//alert(JSON.stringify(ids['userId']));
let playerID = ids['userId'];
//alert(playerID);
});
这对我有用; 试一试。
谢谢@kenef
只需调用OneSignal.configure()
就足以在侦听器'ids'
上发出一个事件。
例如:
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);
}
帮助那些仍然有问题的人获得player_id
。
onIds(device) {
console.log('Device info: ', device);
}
device
返回一个对象。 因此,要真正获得您正在寻找的player_id
,您应该执行类似device.userId
我如何让它在科尔多瓦工作?
@luizmagao你的环境是什么?
你好,我有 quickblox dialogid 我如何使用这个 dialogid 获取 quickblox 用户 ID
只需调用
OneSignal.configure()
就足以在侦听器'ids'
上发出一个事件。例如:
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); }
那么,如何提取 ID 呢? 你能再解释一下吗?
使用 jquery 和其他获取所有玩家 ID/用户 ID。请让我知道这可能与否
最有用的评论
目标是在应用程序启动时从 Onesignal 接收 PlayerID。
所以在 App.js 中为我工作了以下代码: