iOS Question how ? Application_RemoteNotification in backgrond not Event

naifnas

Active Member
Licensed User
I send some message by push notifications with key *.p8
in production.
by PHP to my device ..it work
I received it ..
but Application_RemoteNotification not event when my app backgrond
can please help?

B4X:
#Region  Project Attributes
    #ApplicationLabel: #########
    #Version: 1.0.0
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown

    #PlistExtra: <key>UIViewControllerBasedStatusBarAppearance</key><false/>
    #ATSEnabled: false
    #PlistExtra: <key>UIBackgroundModes</key><array><string>remote-notification</string></array>
    #Entitlement: <key>aps-environment</key><string>production</string>

    #CertificateFile:ios_distribution.cer
    #ProvisionFile:Push.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.43.95:51044"
    Dim RL As ReleaseLogger
    Dim Tokens() As Byte
    Dim send As Boolean

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
     RL.Initialize("192.168.43.95", 54323)

'    Dim no As NativeObject = App
'    no.RunMethod("unregisterForRemoteNotifications", Null)
'    Dim NativeMe As NativeObject = Me
'    NativeMe.RunMethod("openNotificationSettings",Null)
    Dim NativeMe As NativeObject = Me
    Dim isRegged As Boolean
    isRegged=NativeMe.RunMethod("isRegisteredForRemoteNotifications", Null).AsBoolean
    Log(isRegged)
End Sub

Private Sub CheckForPushMessage
    Log("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, CompletionHandler As CompletionHandler)
    Log("Application_RemoteNotification")
    Log($"Message arrived: ${Message}"$)
    Msgbox(Message, "Push message!")
    CompletionHandler.Complete
    send=False

End Sub
Private Sub Application_Background
    Log("EventName_Background")

End Sub
Private Sub Application_Active
    Log("Application_PushToken")

End Sub
#If OBJC
- (void)openNotificationSettings {
   if (&UIApplicationOpenSettingsURLString != NULL)
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
#end if
#If OBJC
- (BOOL)isRegisteredForRemoteNotifications {
    if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications]) return YES;
    return NO;
}
#end if
 
Top