iOS Tutorial Push notifications

Rabbit

Member
Licensed User
Longtime User
Hi,

I did manage to run the push b4i and generate the token
CD32F94AAA8D47C4F210F389D97C35E5DD30717F81FCC4C248FF1D2C3ED12CE5

Would you please insert PHP code for the server? I want to echo to my device from my device this is will help me a lot.

Regards
 

walterf25

Expert
Licensed User
Longtime User
Very nice, i was just going to post a question about whether there was something similar in b4i to Google Cloud Messaging, i'm getting convinced more and more about buying B4i.

Thanks Erel.
Walter
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Instructions were updated to correctly raise the RemoteNotification event if the app is not running.
Example of a complete app:
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: 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.0.6: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
 

Shay

Well-Known Member
Licensed User
Longtime User
I have 2 different apps
(for each I created it's own app id, certificate, provision)
do I need to create another push keystore from ide? or the same can be used for the 2 apps?
 

Shay

Well-Known Member
Licensed User
Longtime User
Thanks, but the question was if I can use the same push keystore or I need to create new one to the second app?
if new one? how can I put 2 files with same name in same directory?
 

Shay

Well-Known Member
Licensed User
Longtime User
@Erel is there a way (or can you make this) to configure paths per app and not global?
 

JanPRO

Well-Known Member
Licensed User
Longtime User
Hi,

when I call the CheckForPushMessage Sub, App.LaunchOptions.ContainsKey("UIApplicationLaunchOptionsRemoteNotificationKey") is always False, so nothing happens. Does anybody knows the answere?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can still use the same key folder. aps_x.cer and push.keystore files are not required during compilation. You only need to use them once to create the keystore and then copy the keystore to the push server (and save a backup in a different folder).
when I call the CheckForPushMessage Sub, App.LaunchOptions.ContainsKey("UIApplicationLaunchOptionsRemoteNotificationKey") is always False, so nothing happens. Does anybody knows the answere?
It will only return true in one specific case.
The questions:
1. Have you clicked on the notification alert?
2. Is RemoteNotification event raised?
 

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
Erel,

In XCODE, when you have in a project a sound (.caf, .mp3, etc), you can send a json push notifications with sound:"nameOfSounf.mp3" for example, and this sound play when notifications arrives, but in B4i I try to put in Special Folder, and Assets, but not working....

B4i needs to put this sound in another special folder?


Thanks

Alberto Iglesias
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…