Private Sub Application_PushToken (Success As Boolean, Token() As Byte)
FirebaseToken = bc.HexFromBytes(Token)
Log("pushtoken: " & FirebaseToken)
End Sub
Private Sub fm_FCMConnected
Log("FCMConnected")
'here we can subscribe and unsubscribe from topics
fm.SubscribeToTopic("ios_general") 'add ios_ prefix to all topics
'modTGIF.FirebaseToken = GetToken
Log("connected token: " & GetToken)
End Sub
Private Sub GetToken As String
Dim no As NativeObject
Dim token As NativeObject = no.Initialize("FIRInstanceID").RunMethod("instanceID", Null).RunMethod("token", Null)
If token.IsInitialized Then Return token.AsString Else Return ""
End Sub
Private Sub Application_RemoteNotification (Message As Map, CompletionHandler As CompletionHandler)
Dim msg As Map = Message
Log($"Message arrived: ${Message}"$)
'get the data from the notification
Dim notifid As String = modMashiane.StateManager.GetSetting("notification")
If notifid = "" Then notifid = "1"
Dim from_id As String = msg.GetDefault("from_id","")
Dim from_token As String = msg.GetDefault("from_token","")
Dim to_id As String = msg.GetDefault("to_id","")
Dim to_token As String = msg.GetDefault("to_token","")
Dim body As String = msg.GetDefault("body","")
Dim title As String = msg.GetDefault("title","")
Dim notif_type As String = msg.GetDefault("notif_type","")
Dim todayJSON As String = msg.GetDefault("currentpage","")
If from_id.Length > 0 And from_token.Length > 0 Then
'save the tokens for later retrieval
modMashiane.StateManager.SetSetting("firebase_" & from_id, from_token)
Log("From Firebase Token Saved.")
End If
If to_id.Length > 0 And to_token.Length > 0 Then
'save the tokens for later retrieval
modMashiane.StateManager.SetSetting("firebase_" & to_id, to_token)
Log("To Firebase Token Saved.")
End If
' only show a notification if its not coming from me
'If from_id <> modTGIF.auser_id Then
Dim n As Notification
n.Initialize(DateTime.Now)
n.PlaySound = True
Select Case notif_type
Case modMashiane.NotifEnum.request
n.AlertBody = body
'n.SetInfo(title, body, frmNotifications)
Case modMashiane.NotifEnum.following
n.AlertBody = body
modMashiane.StateManager.setSetting("otheruser", from_id)
'n.SetInfo(title, body, frmProfileOther)
Case modMashiane.NotifEnum.like
n.AlertBody = body
modMashiane.StateManager.SetSetting("currentpage", todayJSON)
'n.SetInfo(title, body, frmLikes)
Case modMashiane.NotifEnum.comment
n.AlertBody = body
modMashiane.StateManager.SetSetting("currentpage", todayJSON)
'n.SetInfo(title, body, frmComments)
Case Else
n.AlertBody = body
'n.SetInfo(title, body, Null)
End Select
n.Register
'App.ApplicationIconBadgeNumber = 1
'Dim id As Int = notifid
'n.Notify(id)
'id = id + 1
'modMashiane.StateManager.SetSetting("notification",id)
CompletionHandler.Complete
End Sub
Private Sub Application_Active
fm.FCMConnect 'should be called from Application_Active
End Sub
Private Sub Application_Background
fm.FCMDisconnect 'should be called from Application_Background
End Sub