#Region Project Attributes
#ApplicationLabel: Push Demo
#Version: 1.0.0
'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
#iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
#iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
#CertificateFile: ios_development.cer
#ProvisionFile: XXXX.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 tokenid, BoardUrl,DeviceBoardPassword As String
Private TextField1 As TextField
Private Button1 As Button
End Sub
Private Sub Application_Start (Nav As NavigationController)
NavControl = Nav
Page1.Initialize("Page1")
Page1.Title = "Register Form"
Page1.RootPanel.LoadLayout("main")
NavControl.ShowPage(Page1)
App.RegisterUserNotifications(True, True, True)
App.RegisterForRemoteNotifications
CheckForPushMessage
BoardUrl = "https://XXXXXXXXXXX/savedevice.php"
DeviceBoardPassword = "XXXXXXXXXXXX"
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
tokenid=bc.HexFromBytes(Token)
Log("TOKEN = " & tokenid)
Else
Log("Error getting token: " & LastException)
End If
End Sub
Private Sub JobDone(j As HttpJob)
If j.Success Then
If j.JobName="RegisterTask" Then
Msgbox("Registered", "Push Demo")
Else if j.JobName="UnRegisterTask" Then
Msgbox("UnRegistered", "Push Demo")
End If
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.Get("alert"))
End Sub
Private Sub Page1_Resize(Width As Int, Height As Int)
End Sub
Private Sub Application_Background
End Sub
Sub Button1_Click
Dim j As HttpJob
j.Initialize("RegisterTask", Me)
j.Download2(BoardUrl, Array As String("device_password", DeviceBoardPassword, "name", TextField1.Text, "id", tokenid, "devicetype", "2"))
End Sub
Sub Button2_Click
Dim j As HttpJob
j.Initialize("UnRegisterTask", Me)
j.Download2(BoardUrl, Array As String("device_password", DeviceBoardPassword, "name", TextField1.Text, "id", "", "devicetype", "2"))
End Sub