Hi there,
In this tutorial I use onesignal rest api and send device token to onesignal and store it
1. Register in onesignal.com and create an application
2. Export .p12 file from certificate using keychain in mac and upload in OneSignal panel -> App Settings -> push -> Apple Push Certificates
3. Import your .p12 files in setting
4. Import Onesignal class to project (attached)
5. Add this codes to progress_globals in
6. Add this codes to application_start
7. And add subs to Main
Note : In distribution version delete test_type=1 from initialize
8. Now go to push in onesginal and send a push notification
In this tutorial I use onesignal rest api and send device token to onesignal and store it
1. Register in onesignal.com and create an application
2. Export .p12 file from certificate using keychain in mac and upload in OneSignal panel -> App Settings -> push -> Apple Push Certificates
3. Import your .p12 files in setting
4. Import Onesignal class to project (attached)
5. Add this codes to progress_globals in
B4X:
Dim signal as onesginal
Dim applicationId As String = "Application_ID"
Dim appversion as String = "1.1"
6. Add this codes to application_start
B4X:
App.RegisterUserNotifications(True, True, True)
App.RegisterForRemoteNotifications
CheckForPushMessage
7. And add subs to Main
B4X:
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
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
signal.Initialize("app_id="&applicationId&"&device_type=0&device_os="&App.osVersion&"&device_model="&GetDeviceModel&"&identifier="&bc.HexFromBytes(Token)&"&game_version"&appversion&"&test_type=1")
Else
Log("Error getting token: " & LastException)
End If
End Sub
Sub GetDeviceModel As String
' get the device model
Dim device As NativeObject
device = device.Initialize("UIDevice").RunMethod("currentDevice", Null)
Dim name As Object = device.GetField("model").AsString
Return name
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
8. Now go to push in onesginal and send a push notification