iOS Question What is the best way ?

tufanv

Expert
Licensed User
Longtime User
Hello,

I am planning to implement different group for my current app with firebase notifications. What i want to do is , I want to be able to send push messages to members with active subscriptions , and without subscriptions seperately.

Currently we are using :
B4X:
Private Sub fm_FCMConnected
   Log("FCMConnected")
   'here we can subscribe and unsubscribe from topics
   fm.SubscribeToTopic("ios_general") 'add ios_ prefix to all topics
End Sub

but i think this event fires as soon as the applicaiton is active so it is before the check of subscription status. How can i change the method to subscribe to paidmembers topic if the subscription is active , if the subscription ended delete from paidmembers topic and subscribe to freemembers topic.

I cant use fm.subscribetopic or unsucbscribe from outside the fcmconnected event also .

I would be happy if you can give a clue about it .Thanks

edit: Also lets say the users subscription has ended but he did not launch the app on purpose to continue receive push messages like a subscribed member. İf he does not launch the app , i wont be able to check if the users subscription has ended so i wont be able to delete him from the paidmembers topic and he will continue to receive push messages for the paid members ( do not think these messages like advertising these are premium push messages to send news for example )
 
Last edited:

tufanv

Expert
Licensed User
Longtime User
Your code is wrong. You should only call CompletionHandler.Complete after the job has finished. You can store it in a global variable.
I did as you say. The problem is for some reason, after i send the first push it come without problem. But sometimes just after 2-3 minutes when i send the message, the remotenotification does not come. I navgiate back to app and see that the app is opening from the begining which means something crashes my app after message comes. With releaselogger i dont see any log , so I tried it with debug mode and try my luck to see the error msg .altough you said do not try with debug mode , message wont arrive , message arrived and after sometime it gave an error like this :
B4X:
Can't endBackgroundTask: no background task exists with identifier 2cceba, or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.

After your advice i changed my remotebotification code to :

B4X:
Private Sub Application_RemoteNotification (Message As Map)

   Log("Message arrived:")
   mesajbody=Message.Get("body")
Dim connection As HttpJob
                     connection.Initialize("durumcheck",Me)
                     connection.download2("https://www.ctmobilesoft.com/tahminhaneapp/tahminhane.php", Array As String ("action", "13", "girdi1", txtusername.text, "girdi2", txtpassword.text,"girdi3","209","girdi4","11","girdi5",lblnuser.Text,"girdi6",lblnpass.text))



   
End Sub

and underjobdone :

B4X:
If Job.JobName="durumcheck" Then
    If Job.Success = True Then
                    Dim res As String
                    Dim m As Map
                    res = Job.GetString
                    Dim parser As JSONParser
                    parser.Initialize(res)
                    Log("Response from server: " & res)
                    If res.Contains("tahmin") Then
                            Dim ln As Notification
    ln.Initialize(DateTime.Now ) '6 seconds from now
    ln.AlertBody = mesajbody
   
    ln.PlaySound = True
    ln.Register
    Log("logbu:" &mesajbody)
    Else
                                    Dim ln As Notification
    ln.Initialize(DateTime.Now ) '6 seconds from now
    ln.AlertBody = "Canlı Tahmin Paylaşıldı. Canlı tahmin sadece üyelerimize açıktır."
    ln.PlaySound = True
    ln.Register
       
                    End If
                    Job.Release
                    CompletionHandler.Complete
End If
End If
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
I don't see how your code can compile. Where is CompletionHandler set?
I set it in process globals
Dim completionhandler as completionhandler

Then under jobdone i have completionhandler.complete

Thats all
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
It looks like you are using the old RemoteNotification event signature. The one without CompletionHandler.
no it was with CompletionHandler. but because you said you have to use CompletionHandler.complete after httpjob done i also stored in globals and deleted from remotenotification event because when there are 2 declarations it gives error : can't cast ..
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
I'm sorry but I don't understand. Please post the complete code.
it is a big project so i cant paste the code here but everything related to remote notificatios are below :

Under Globals I have :

B4X:
    Dim CompletionHandler As CompletionHandler

remotenotificaiton event : ( when remote notification comes , i send the users username and password to server to check if he has a subscription )

B4X:
Private Sub Application_RemoteNotification (Message As Map)

   Log("Message arrived:")
   mesajbody=Message.Get("body")
Dim connection As HttpJob
                     connection.Initialize("durumcheck",Me)
                     connection.download2("https://www.ctmobilesoft.com/tahminapp/xx.php", Array As String ("action", "13", "girdi1", txtusername.text, "girdi2", txtpassword.text,"girdi3","209","girdi4","11","girdi5",lblnuser.Text,"girdi6",lblnpass.text))



  
End Sub

under jobdone i have : ( if user has subscription make a different notification and if not make another notification ) .

B4X:
If Job.JobName="durumcheck" Then
    If Job.Success = True Then
                    Dim res As String
                    Dim m As Map
                    res = Job.GetString
                    Dim parser As JSONParser
                    parser.Initialize(res)
                    Log("Response from server: " & res)
                    If res.Contains("tahmin") Then
                            Dim ln As Notification
    ln.Initialize(DateTime.Now ) '6 seconds from now
    ln.AlertBody = mesajbody
  
    ln.PlaySound = True
    ln.Register
    Log("logbu:" &mesajbody)
    Else
                                    Dim ln As Notification
    ln.Initialize(DateTime.Now ) '6 seconds from now
    ln.AlertBody = "Canlı Tahmin Paylaşıldı. Canlı tahmin sadece üyelerimize açıktır."
    ln.PlaySound = True
    ln.Register
      
                    End If
                    CompletionHandler.Complete
End If
End If

job.release

This works sometimes. But lets say i send a message and it came without problem , i do nothing on my phone and send another msg after 5 minutes. Them message does not come . So i click on the app and see that app is closed completely and it launchs from the begining. So something is crashing the app i think.
if it is not enogh i can send the whole code to your mail ..
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
It should be:
B4X:
Sub Application_RemoteNotification (Message As Map, CompletionHandler1 As CompletionHandler)
   '...
   CompletionHandler = CompletionHandler1
End Sub
after the first message second one is not coming and i see that the app is launching from the begining again. I cant see any error log why the app was closed with releaselogger. Is there a more advanced way of finding crash apps for my app ? so maybe i can find the problem with that ?
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
The app can be killed after the first message. This is expected. If you think that there is a crash then remove all the code except of the local notification and run some tests.
But when the app is killed other messages does not wake up the phone and messagearrived is not triggered. Thats why i am thinking maybe something crashes the app and that avoids the new messages. hard to understand..
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
The app can be killed after the first message. This is expected. If you think that there is a crash then remove all the code except of the local notification and run some tests.
by the way i found out now that
what you stated in the silent push tutorial :
In order to test it you need to compile it in Release mode and run it once.
Now install the app again and do not start it. Send a silent push message and the process should start.

this does not happen with my app. If i install the app and do not run it , the process not starts . I have to launch the app press the home button then when i send message it arrives. Can this be a clue about stg ?= ( also i get : The default app has not been configured yet. error at every launch, i think it has stg to do with firebase )
 
Last edited:
Upvote 0

tufanv

Expert
Licensed User
Longtime User
Please create a new project with only the push related code. If it doesn't work then upload the project and I'll test it.
I will test with a new app in a few days but by the way i saw that after adding msgbox(message) tp remotenotificaitopn event , sometimes the push comes and when they do not come , if i launch the app, all of them come one by one ..
 
Upvote 0
Top