iOS Question Push Notification - Event RemoteNotification never raised

Juan Marrero

Active Member
Licensed User
Longtime User
I created a new non-wildcard App ID, a new Certificate and a new Provisioning Profile at, everything for push notification. I copied the code from B4i-Push example, referenced the new provisioning profile and created a new push.keystore. When the app compiles it registers the token in B4X Push Server (I can see it in the logs), but when I send the push message, the app never raise the event Application_RemoteNotification. In Android works perfectly.

Juan Marrero

Active Member
Licensed User
Longtime User
This is part of my code:

#Region  Project Attributes
   #ApplicationLabel: MyApp
   #Version: 1.0.0
   'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
   #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
   #iPadOrientations: Portrait, PortraitUpsideDown, LandscapeLeft, LandscapeRight
   #ProvisionFile: prusbpush.mobileprovision
#End Region
Sub Process_Globals
Public App As Application
   Public NavControl As NavigationController
   Private MainPage As Page
   Private Resized As Boolean = False
   Private Const ServerUrl As String = ""
   Private Normal As Int = 0
   Private btnBrands As Button
   Private btnContactUs As Button
   Private btnEvents As Button
   Private btnFacebook As Button
   Private btnWebpage As Button
   Private btnYoutube As Button
   Private ImageView1 As ImageView
   Private ImageView2 As ImageView
   Private ImageView3 As ImageView
   Private ImageView4 As ImageView
   Private lblBrands As Label
   Private lblContactUs As Label
   Private lblEvents As Label
   Private lblFacebook As Label
   Private lblInternet As Label
   Private lblYoutube As Label
   Private Panel1 As Panel
   Private Panel2 As Panel
   Private Panel3 As Panel
End Sub

Private Sub Application_Start (Nav As NavigationController)
   Dim devLO As LayoutValues = GetDeviceLayoutValues

   NavControl = Nav
   MainPage.Title = "Bike Stop"
   MainPage.RootPanel.Color = Colors.White
   MainPage.HideBackButton = True
   MainPage.RootPanel.Width = devLO.Width
   MainPage.RootPanel.Height = devLO.Height - ModMain.MinusBars
   App.RegisterUserNotifications(True, True, True)

   MainPage_Resize(devLO.Width, devLO.Height - ModMain.MinusBars)
   Resized = True
End Sub

Private Sub CheckForPushMessage
  If App.LaunchOptions.IsInitialized And App.LaunchOptions.ContainsKey("UIApplicationLaunchOptionsRemoteNotificationKey") Then
  Dim data As Object = App.LaunchOptions.Get("UIApplicationLaunchOptionsRemoteNotificationKey")
  Dim no As NativeObject = App
  no.GetField("delegate").RunMethod("application:didReceiveRemoteNotification:", Array(App, data))
  End If
End Sub

Private Sub Application_PushToken (Success As Boolean, Token() As Byte)
   If Success Then
     Dim bc As ByteConverter
     Dim j As HttpJob
     j.Initialize("j", Me)
     j.PostString(ServerUrl & "/devicetoken", "token=" & bc.HexFromBytes(Token) & "&type=1")
     Log("Error getting token: " & LastException)
   End If
End Sub

Private Sub JobDone(j As HttpJob)
   If j.Success Then
     Log("Token uploaded successfully.")
     Log("Error uploading token")
   End If
End Sub

Private Sub Application_RemoteNotification (Message As Map)
   Log("Remote notification: " & Message)
   Dim m As Map = Message.Get("aps")
   Msgbox("remote: " & Message, "")
End Sub

The Certificate and Provisioning Profile are for development. Haven't tried distribution yet.
Upvote 0

Juan Marrero

Active Member
Licensed User
Longtime User
It is called. This is what i get in the logs:

Program started.
2016-01-05 09:38:36.321:INFO::main: Logging initialized @1687ms
2016-01-05 09:38:36.528:INFO:eek:ejs.Server:main: jetty-9.1.z-SNAPSHOT
2016-01-05 09:38:36.595:WARN:eek:ejh.MimeTypes:main: java.util.MissingResourceException: Can't find bundle for base name org/eclipse/jetty/http/encoding, locale en_US
2016-01-05 09:38:36.613:INFO:eek:ejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@6ea6d14e{/,file:/O:/B4X-PushServer/PushServer/Objects/www,AVAILABLE}
2016-01-05 09:38:36.629:INFO:eek:ejs.AbstractNCSARequestLog:main: Opened O:\B4X-PushServer\PushServer\Objects\logs\b4j-2016_01_05.request.log
2016-01-05 09:38:36.762:INFO:eek:ejs.ServerConnector:main: Started ServerConnector@3b81a1bc{HTTP/1.1}{}
2016-01-05 09:38:36.763:INFO:eek:ejs.Server:main: Started @2147ms
Emulated network latency: 100ms
server version: 0.95
server is listening on port: 51044
Socket connected.
Feedback Socket connected.
feedback terminated
Token added: 5141BBB84224F0D7B619B046D5404B4F8DD3DBEEE1C9B50BE0340B5B2E33717A
send message to
Trying to reconnect...
Message was sent successfully
Socket connected.
Upvote 0

Juan Marrero

Active Member
Licensed User
Longtime User
Installed new B4J version.

You are trying to send to an invalid token. Maybe a development token. Delete the three files of the push.db to clear the database.

Clearing the database fixed my problem. Now push notifications are working. A thousand Thanks!!
Upvote 0