iOS Question Push notification does not arrives

Descartex

Well-Known Member
Licensed User
Longtime User
Hi everyone!!
I'm need to manage push notifications for my app and I earned to communicate with the B4J Push Server, as it log says:
B4X:
2016-05-12 11:51:43.046:INFO::main: Logging initialized @1116ms
2016-05-12 11:51:43.769:INFO:oejs.Server:main: jetty-9.3.z-SNAPSHOT
2016-05-12 11:51:43.848:INFO:oejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@a4a92b{/,file:///L:/GCM/PushServer/Objects/www,AVAILABLE}
2016-05-12 11:51:43.870:INFO:oejs.AbstractNCSARequestLog:main: Opened L:\GCM\PushServer\Objects\logs\b4j-2016_05_12.request.log
2016-05-12 11:51:44.016:INFO:oejs.ServerConnector:main: Started ServerConnector@1a76ffa{HTTP/1.1,[http/1.1]}{0.0.0.0:51044}
2016-05-12 11:51:44.016:INFO:oejs.Server:main: Started @2088ms
server version: 0.97
server is listening on port: 51044
Table: tokens
Token added: 9F25E757BED9D5D4DE3861D69F648ADA843BA70F1E62221408C8324F125D66DF
send message to
Message was sent successfully
Token added: 9F25E757BED9D5D4DE3861D69F648ADA843BA70F1E62221408C8324F125D66DF
send message to
Message was sent successfully

And the code of my B4i Project is:
B4X:
#Region  Project Attributes
    #ApplicationLabel: B4i Example
    #Version: 1.0.0
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
    #ProvisionFile: my_example.mobileprovision
#End Region

Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'Public variables can be accessed from all modules.
   Public App As Application
   Public NavControl As NavigationController
   Private Page1 As Page
   Private Const ServerUrl As String = "http://192.168.0.101:51044"
End Sub

Private Sub Application_Start (Nav As NavigationController)
   NavControl = Nav
   Page1.Initialize("Page1")
   Page1.Title = "Page 1"
   Page1.RootPanel.Color = Colors.White
   NavControl.ShowPage(Page1)
   App.RegisterUserNotifications(True, True, True)
   App.RegisterForRemoteNotifications
   CheckForPushMessage
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")
   Else
     Log("Error getting token: " & LastException)
   End If
End Sub

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

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

But I have no idea why notification does not arrives...

Thank you in advance.
 

marcick

Well-Known Member
Licensed User
Longtime User
The code looks ok.
Did you follow this steps ?

The following steps are required inside Apple developer console:
1. Create a new explicit (non-wildcard) App ID with the package name of the push app. For example anywheresoftware.b4i.push. Enable push notification service.
2. Create an Apple Push Notification SSL certificate (start with Development). Use the same certSigningRequest.csr file that you previously created.
3. Create a provision file with the new App ID.
 
Upvote 0

Descartex

Well-Known Member
Licensed User
Longtime User
Hi, thanks for answering.
Yes, @marcick, i´ve done all these steps 3 times from the scratch. but it stills not working :(

Yes, @Erel, i´m running on release mode...

I dont know what im doing wrong...
 
Upvote 0

Descartex

Well-Known Member
Licensed User
Longtime User
Hi.
Thanks both for the help...
Those lines where commented, but when uncommented, server log raised certificates errors, so i created again (for the 4th time) from the scratch... and worked at least.

This means i've done something wrong... but i've repeated for 3 times...

Sorry and thanks again.
 
Upvote 0
Top