In my app, I have setup a notification system using OneSignal and Firebase. However, when I prompt the OneSignal Notification Alert and the user allows notifications, the userID/playerID returns nil. Here is the following code:
static func getNotificationPermissionsAndStorePlayerIdInFireabse(currentUserId: String) {
OneSignal.inFocusDisplayType = OSNotificationDisplayType.notification
OneSignal.promptForPushNotifications(userResponse: { accepted in
if accepted == true {
let status: OSPermissionSubscriptionState = OneSignal.getPermissionSubscriptionState()
let userID = status.subscriptionStatus.userId
let pushToken = status.subscriptionStatus.pushToken
if pushToken != nil {
if let playerID = userID {
FIRDatabase.database().reference().child("users").child(currentUserId).child("oneSignal").setValue([playerID: pushToken!])
}
}
}
})
}
In the code above I access the userID and push token, however, the userID returns nil. The push token, on the other hand, has a value. I don't know why the userId is nil. Any help would be appreciated.
PS: Please note I call this function after my user logs in.