Rating:
4
Joined: Sep 1, 2014
Company: Smart ID Dynamics
Hello Timofey.
Can you give me a code sample for using PushNotification service on local mobile platform and between mobile application and main infobase on the server?
Sorry for the late reply. Here are examples of sending and receiving push notifications:
Sending push notifications.
Code
// Creating push notification.
Notification = New DeliverableNotification;
// SubscriberID - ID of the notification recipient, that you have to get from
// the recipient using any available method.
Notification.Recipients.Add(SubscriberID);
Notification.Text = NStr("en = 'Some sample text'");
Notification.SoundAlert = SoundAlert.None;
Notification.Badge = 2;
// Sending push notification.
// AuthenticationData - depends on the recipient's OS.
// - for Android - the GCM service connection string.
// - for iOS - the APNs connection certificate file.
DeliverableNotificationSend.Send(Notification, AutenticationData);
Receiving push notifications.
Code
Procedure OnStart()
// Get your ID and send to the sender using any available method.
ApplicationNumber = "1234567890";
SubscriberID = DeliverableNotifications.ReceiveNotificationSubscriberID(ApplicationNumber);
// ...
// Attaching the push event handler on the application start.
DeliverableNotifications.AttachNotificationHandler("OnReceiveNotification");
EndProcedure
// Handling the received notification.
Procedure OnReceiveNotification(Notification, IsLocal, IsDisplayed) Export
If IsLocal Then
Message(StringFunctionsClientServer.SubstituteParametersInString(
NStr("en = 'Received a local notification with following text: %1'"), Notification.Text);
Else
Message(StringFunctionsClientServer.SubstituteParametersInString(
NStr("en = 'Received a push notification with following text: %1'"), Notification.Text);
EndIf;
EndProcedure
Rating:
4
Joined: Sep 1, 2014
Company: Smart ID Dynamics
Yes.
The code is in Managed Application module.
The code is:
Code
// Handling the received notification.
Procedure ReceivePushNotification(Notification, IsLocal, IsDisplayed)
If IsLocal Then
Message("Received a local notification with following text:" + Notification.Text);
Else
Message("Received a push notification with following text:" + Notification.Text);
EndIf;
EndProcedure
Procedure OnStart()
SetApplicationCaption("Smart Selling " + Commons.GetVersion());
#If MobileAppClient Then
DeliverableNotifications.AttachNotificationHandler("ReceivePushNotification");
#EndIf
EndProcedure
// Get your ID and send to the sender using any available method.
// You need to use some string as an identifier of the application. Maybe an email or login of a user.
ApplicationNumber = "1234567890";
SubscriberID = DeliverableNotifications.ReceiveNotificationSubscriberID(ApplicationNumber);
// Send the subscriber ID to the sender, for example using web service of the server application.
// ...
I tried to use the following code in managed application module and all it gives me are errors. Can you help me please?
Procedure OnStart()
// Get your ID and send to the sender using any available method. ApplicationNumber = "1234567890"; SubscriberID = DeliverableNotifications.ReceiveNotificationSubscriberID(ApplicationNumber); // ...
EndProcedure
Error: msg "{ManagedApplicationModule(7)}: Error calling context method (ReceiveNotificationSubscriberID): Cannot get the push notification subscriber ID." String
Rating:
8
Joined: Jun 25, 2013
Company: 1C Company
Hello, Sebastian,
I'm afraid, we've got not enough details to help you. Can you provide us with .cf file of your application? Please send it to int@1c.ru for Sergey Polikarpov if you do.
I write as this: UseGCM = Constants.UseGCM.Get(); Notification = New DeliverableNotification; Notification.Title = "Test"; Notification.Text = "Content"; Notification.SoundAlert = SoundAlert.Default;
Records = InformationRegisters.MáyTrạm.Select(,); While Records.Next() Do Notification.Recipients.Add(Records.NotificationID.Get()); Message("Added"); EndDo; AuthenticationData = New Map(); If UseGCM = True Then AuthenticationData[DeliverableNotificationSubscriberType.GCM] = Constants.GCMSenderServerKey.Get(); EndIf; DeliverableNotificationSend.Send(Notification, AuthenticationData);
---------------------- When program is running, it shown the error: "wrong parameter 2" (AuthenticationData) I do not know why? (I have registered Google Key)
Thank you, I have created APNS certificate. But now, the command "SubscriberID = DeliverableNotifications.ReceiveNotificationSubscriberID("");" have error "Cannot receive name (ID) of Push register" on iOS device. Help me, please!
#If MobileClient Then DeliverableNotifications.AttachNotificationHandler("ĐọcThôngBáo"); ApplicationNumber = DùngChung.ỨngDụngGoogle(); If DùngChung.NSDIOS(NSDHiệnTại) Then //This command notice error when It run on iOS system SubscriberID = DeliverableNotifications.ReceiveNotificationSubscriberID(""); DùngChung.LưuSID(SubscriberID, NSDHiệnTại); Else SubscriberID = DeliverableNotifications.ReceiveNotificationSubscriberID(ApplicationNumber); DùngChung.LưuSID(SubscriberID, NSDHiệnTại); EndIf; #EndIf