iOS Question Push extension

fishwolf

Well-Known Member
Licensed User
Longtime User
I'm tring to send push with title attribute, child of alert.
i receive the push with success, but i clicked on push and run the app, the event show the data in this mode

B4X:
Remote notification: NSMapTable {
[5] aps -> (read only map) {
  alert =  {
  body = "my body bla, bla";
  title = MyTitle;
  };
  badge = 34;
  sound = "notification.mp3";
}

I have notice that the title value is not return as string (without comma),
i would use this field as selector for show the specific page.
 
Last edited:

fishwolf

Well-Known Member
Licensed User
Longtime User
Can you post the server code that creates the json payload?

B4X:
replace this line
Dim m As Map =  CreateMap("alert": msg.Text, "badge": msg.Badge)
with
Dim alert As Map =  CreateMap("title": "my title", "body": "my body")
Dim m As Map =  CreateMap("alert": alert, "badge": msg.Badge)

i had tried to use a php push server with the same json payload, title or custom field are without comma, other fields are OK.

exist a specific encode or data format?
why some fields are ok and other no?
 
Upvote 0

fishwolf

Well-Known Member
Licensed User
Longtime User
yes, it's correct, if i use a string with 2 word, the comma are present.

B4X:
Private Sub Application_RemoteNotification (Message As Map)
  
   Dim ApsMap As Map = Message.Get("aps")
   Log("Aps=" & ApsMap)
  
   Dim AlertMap As Map = ApsMap.Get("alert")
   Log("Alert=" & AlertMap)
  
   Dim BodyText As String = AlertMap.Get("body")
   Log("Body="  & BodyText)
  
   Dim TitleText As String = AlertMap.Get("title")
   Log("Title=" & TitleText)
 

log

Aps=(read only map) {
  alert =  {
  body = "my body";
  title = "my title";
  };
  badge = 34;
  sound = "notification.mp3";
}
Alert={
  body = "my body";
  title = "my title";
}
Error occurred on line: 83 (main)
Method not found: Get:, target: {
  body = "my body";
  title = "my title";
}
Stack Trace: (
  CoreFoundation  <redacted> + 150
  libobjc.A.dylib  objc_exception_throw + 38
  CoreFoundation  <redacted> + 0
  Info Agility  +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 438
  Info Agility  -[B4IShell runMethod:] + 496
  Info Agility  -[B4IShell raiseEventImpl:method:args::] + 1846
  Info Agility  -[B4IShellBI raiseEvent:event:params:] + 1316
  Info Agility  __33-[B4I raiseUIEvent:event:params:]_block_invoke + 74
  libdispatch.dylib  <redacted> + 10
  libdispatch.dylib  <redacted> + 22
libdispatch.dylib  _dispatch_main_queue_callback_4CF + 1330
CoreFoundation  <redacted> + 8
CoreFoundation  <redacted> + 1512
CoreFoundation  CFRunLoopRunSpecific + 476
CoreFoundation  CFRunLoopRunInMode + 106
GraphicsServices  GSEventRunModal + 136
UIKit  UIApplicationMain + 1440
Info Agility  main + 108
libdyld.dylib  <redacted> + 2
)

work fine with the simple alert structure
B4X:
Private Sub Application_RemoteNotification (Message As Map)
   
   Dim ApsMap As Map = Message.Get("aps")
   Log("Aps=" & ApsMap)
   
   Dim AlertMap As Map = ApsMap.Get("alert")
   Log("Alert=" & AlertMap)
  
log

Aps=(read only map) {
  alert = "my title-my body";
  badge = 34;
  sound = "notification.mp3";
}
Alert=my title-my body
 
Upvote 0

fishwolf

Well-Known Member
Licensed User
Longtime User
this error is a my parsing error or a bug?

B4X:
Error occurred on line: 83 (main)
Method not found: Get:, target: {
 body = "my body";
 title = "my title";
}
Stack Trace: (
 CoreFoundation <redacted> + 150
 libobjc.A.dylib objc_exception_throw + 38
 CoreFoundation <redacted> + 0
 Info Agility +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 438
 Info Agility -[B4IShell runMethod:] + 496
 Info Agility -[B4IShell raiseEventImpl:method:args::] + 1846
 Info Agility -[B4IShellBI raiseEvent:event:params:] + 1316
 Info Agility __33-[B4I raiseUIEvent:event:params:]_block_invoke + 74
 libdispatch.dylib <redacted> + 10
 libdispatch.dylib <redacted> + 22
libdispatch.dylib _dispatch_main_queue_callback_4CF + 1330
CoreFoundation <redacted> + 8
CoreFoundation <redacted> + 1512
CoreFoundation CFRunLoopRunSpecific + 476
CoreFoundation CFRunLoopRunInMode + 106
GraphicsServices GSEventRunModal + 136
UIKit UIApplicationMain + 1440
Info Agility main + 108
libdyld.dylib <redacted> + 2
)
 
Upvote 0

fishwolf

Well-Known Member
Licensed User
Longtime User
Dim BodyText As String = AlertMap.Get("body") or title

B4X:
#Region  Project Attributes
   #ApplicationLabel: Push Parsing
   #Version: 1.0.0
   'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
   #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
   #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
   #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://www.push_server/"
End Sub

Private Sub Application_Start (Nav As NavigationController)
   NavControl = Nav
   Page1.Initialize("Page1")
   Page1.Title = "MyTitle"
   Page1.RootPanel.Color = Colors.White
   NavControl.ShowPage(Page1)
   App.RegisterUserNotifications(True, True, True)
   App.RegisterForRemoteNotifications
   
   App.ApplicationIconBadgeNumber = 5
End Sub

Private Sub Application_PushToken (Success As Boolean, Token() As Byte)

   If Success Then
     Dim bc As ByteConverter
     Dim j As HttpJob
     
     Log ("Token: " & bc.HexFromBytes(Token))
     
     j.Initialize("j", Me)
     j.PostString(ServerUrl & "/devicetoken", "token=" & bc.HexFromBytes(Token) & "&type=1")

   Else
     Log("Error getting token: " & LastException)
     Msgbox("Error getting token: " & LastException, "Debug")
   End If
End Sub

Private Sub JobDone(Job As HttpJob)

   Log("JobName = " & Job.JobName & ", Success = " & Job.Success & ", Tag = " & Job.Tag)

   If Job.Success Then
     Log(Job.GetString)
     
     Log("Token uploaded successfully.")
   Else
     Log("Error uploading token")
   End If
   
   Job.Release
   
End Sub

Private Sub Application_RemoteNotification (Message As Map)
   
   Dim ApsMap As Map = Message.Get("aps")
   Log("Aps=" & ApsMap)
   
   Dim AlertMap As Map = ApsMap.Get("alert")
   Log("Alert=" & AlertMap)
   
   Dim BodyText As String = AlertMap.Get("body")
   Log("Body="  & BodyText)
   
   Dim TitleText As String = AlertMap.Get("title")
   Log("Title=" & TitleText)
   
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
   
End Sub

Private Sub Application_Background
   
End Sub
 
Upvote 0

fishwolf

Well-Known Member
Licensed User
Longtime User
i have install v2.30 beta and i have the similar error

B4X:
Private Sub Application_RemoteNotification (Message As Map)

Dim ApsMap As Map = Message.Get("aps")
    Log("Aps=" & ApsMap)
  
    Dim AlertMap As Map = ApsMap.Get("alert")
    Log("Alert=" & AlertMap)
  
 83 line   Dim BodyText As String = AlertMap..Get("body")
    Log("Body="  & BodyText)

Application_Remotenotification
Aps=(read only map) {
    alert =     {
        body = "my body";
        title = "my title";
    };
    badge = 34;
    sound = "notification.mp3";
}
Alert={
    body = "my body";
    title = "my title";
}
Error occurred on line: 83 (Main)
-[__NSCFDictionary Get:]: unrecognized selector sent to instance 0x17e727c0
Stack Trace: (
  CoreFoundation       <redacted> + 150
  libobjc.A.dylib      objc_exception_throw + 38
  CoreFoundation       <redacted> + 0
  CoreFoundation       <redacted> + 714
  CoreFoundation       _CF_forwarding_prep_0 + 24
  Info Agility         -[b4i_main _application_remotenotification:] + 2012
  CoreFoundation       <redacted> + 68
  CoreFoundation       <redacted> + 300
  Info Agility         +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1786
  Info Agility         -[B4IShell runMethod:] + 574
Info Agility         -[B4IShell raiseEventImpl:method:args::] + 1998
Info Agility         -[B4IShellBI raiseEvent:event:params:] + 1340
Info Agility         __33-[B4I raiseUIEvent:event:params:]_block_invoke + 74
libdispatch.dylib    <redacted> + 10
libdispatch.dylib    <redacted> + 22
libdispatch.dylib    _dispatch_main_queue_callback_4CF + 1330
CoreFoundation       <redacted> + 8
CoreFoundation       <redacted> + 1512
CoreFoundation       CFRunLoopRunSpecific + 476
CoreFoundation       CFRunLoopRunInMode + 106
GraphicsServices     GSEventRunModal + 136
UIKit                UIApplicationMain + 1440
Info Agility         main + 108
libdyld.dylib        <redacted> + 2
)
 
Upvote 0

fishwolf

Well-Known Member
Licensed User
Longtime User
installed 2.30, all fields are available without errors, Thanks

I have notice that the "Application_RemoteNotification" event is called only if the app is running.
if i click on notification (menu or stand-by) with the app closed, the app is open, but the event is not called.
Is correct?
 
Upvote 0
Top