Я только начал работать с onesignal и некоторое время работал с firebase, но без эксперта.Я создаю UserID или PlayerID (для одного сигнала userID означает PlayerID, но я могу ошибаться) и pushToken.В моем проекте у меня есть 3 разных типа профилей, и так как у меня есть люди, которые уже загрузили мое приложение, я хочу сохранить UserID и PushToken для своего ребенка в firebase, а также проверить, есть ли они уже, чтобы они не дублировались.,Сейчас в моем тестировании оба профиля были сгенерированы с одним и тем же идентификатором пользователя и PushToken, это правильно или я что-то не так делаю?
OneSignal.initWithLaunchOptions(launchOptions, appId: "219d78bc-1060-4d98-bdf9-6d57930f64f2", handleNotificationReceived: { (notification) in
}, handleNotificationAction: { (result) in
let payload: OSNotificationPayload? = result?.notification.payload
print(payload ?? "")
}, settings: [kOSSettingsKeyAutoPrompt : false, kOSSettingsKeyInFocusDisplayOption: OSNotificationDisplayType.notification.rawValue])
let status: OSPermissionSubscriptionState = OneSignal.getPermissionSubscriptionState()
let userID = status.subscriptionStatus.userId
print("userID = \(userID)")
let pushToken = status.subscriptionStatus.pushToken
print("pushToken = \(pushToken)")
if pushToken != nil {
if let playerID = userID {
func checkIfBusinessLoggedIn() {
Database.database().reference().child("Businesses").child((Auth.auth().currentUser?.uid)!).observeSingleEvent(of: .value, with: { snapshot in
if snapshot.exists() {
print("Business is Signed In")
Database.database().reference().child("Businesses").child((Auth.auth().currentUser?.uid)!).queryOrdered(byChild: "onesignal").queryEqual(toValue: "onesignal").observeSingleEvent(of: .value, with: { snapshot in
if snapshot.exists() {
print("onesignal exists for business do not add value")
} else {
print("onesignal does not exist for business please add value")
Database.database().reference().child("Businesses").child((Auth.auth().currentUser?.uid)!).child("onesignal").setValue([userID!: pushToken!])
}
})
} else {
print("Business is NOT signed in")
}
})
}
checkIfBusinessLoggedIn()
func checkIfCustomerLoggedIn() {
Database.database().reference().child("employees").child((Auth.auth().currentUser?.uid)!).observeSingleEvent(of: .value, with: { snapshot in
if snapshot.exists() {
print("Employee is Signed In")
Database.database().reference().child("employees").child((Auth.auth().currentUser?.uid)!).queryOrdered(byChild: "onesignal").queryEqual(toValue: "onesignal").observeSingleEvent(of: .value, with: { snapshot in
if snapshot.exists() {
print("onesignal employee exists do not add value")
} else {
print("onesignal employee does not exist please add value")
Database.database().reference().child("employees").child((Auth.auth().currentUser?.uid)!).child("onesignal").setValue([userID!: pushToken!])
}
})
} else {
print("Employee is NOT signed in")
}
})
}
checkIfCustomerLoggedIn()
func checkIfEmployeeLoggedIn() {
Database.database().reference().child("user_profiles").child((Auth.auth().currentUser?.uid)!).observeSingleEvent(of: .value, with: { snapshot in
if snapshot.exists() {
print("Customer is Signed In")
Database.database().reference().child("user_profiles").child((Auth.auth().currentUser?.uid)!).queryOrdered(byChild: "onesignal").queryEqual(toValue: "onesignal").observeSingleEvent(of: .value, with: { snapshot in
if snapshot.exists() {
print("onesignal customer exists do not add value ")
} else {
print("onesignal customer does NOT exist please add value ")
Database.database().reference().child("user_profiles").child((Auth.auth().currentUser?.uid)!).child("onesignal").setValue([userID!: pushToken!])
}
})
} else {
print("Customer is NOT singed in")
}
})
}
checkIfEmployeeLoggedIn()
}
}
![enter image description here](https://i.stack.imgur.com/x3zeE.png)