Rating:
5
Joined: Mar 29, 2016
Company: DND YAZILIM LTD.
Hi,
I working on push notification. My code is:
Mobile;
//managed application module
Code
Procedure OnStart()
UpdateClientID();
AttachIdleHandler("Connectable_UpdateFollowingID", 7200);
#If MobileAppClient Then
DeliverableNotifications.AttachNotificationHandler("Plugin_ProcessingNotifications");
#EndIf
EndProcedure
Procedure Connectable_UpdateFollowingID() Export
UpdateClientID();
EndProcedure
Procedure UpdateClientID()
#If MobileAppClient Then
mProjectNumber = CommonCallServer.GetProjectNumber();
If IsBlankString(mProjectNumber) Then
Return;
EndIf;
Try
SubscriberID = DeliverableNotifications.ReceiveNotificationSubscriberID(mProjectNumber);
Except
Message(ErrorDescription());
Return;
EndTry;
mQueryOptions = New Structure("ServerAddress, NameBase, ClientID");
// указываем IP Сервера, он может быть как локальный, так и нет
mQueryOptions.ServerAddress = "192.168.0.14";
// имя базы, под которым она была опубликована на вэб сервере
// о том, как выполнить публикацию информации в Интернете информации предостаточно
mQueryOptions.NameBase = "GELAL";
mQueryOptions.ClientID = SubscriberID;
CommonCallServer.SendIDToServer(mQueryOptions);
#EndIf
EndProcedure
Procedure Plugin_ProcessingNotifications(Notification, IsLocal, IsShow) Export
// просто сообщим тест пуша
Message(Notification.Text);
#If MobileAppClient Then
MultimediaTools.PlaySoundAlert(SoundAlert.Default,True);
Noti = New DeliverableNotification;
Noti.Title = Notification.Text;
Noti.Text = Notification.Text;
Noti.SoundAlert = SoundAlert.Default;
DeliverableNotifications.AddLocalNotification(Noti);
#EndIf
EndProcedure
It is working. my mobile device get id from firebase and update server constant is clientID.
Than, i was try send a deliverablenotification on server to mobile device.
We are still investigating the samples you sent us.
Meanwhile we recommend you to add the 5th parameter to the call to the DeliverableNotificationSend.Send() method in your code.
The parameter (DeliverableNotificationSendIssuesInformation) is to get information from 1C:Enterprise platform about issues that occurred when sending notifications via the call.
Type: Array. Contains the details of deliverable notification sending issues. It is an array of elements of DeliverableNotificationSendingIssueInformation type. >>
Rating:
5
Joined: Mar 29, 2016
Company: DND YAZILIM LTD.
Dear Vladimir,
Thanks!
I will try on 1C:Enterprise 8.3.13.1513 PC Platform and 8.3.12.64 Mobile Platform that code.
My android version: Android 8.0.0 My android device: Huawei bla-l09 (huawei mate 10 pro)
When app is opened notification is received!
But when app is not opened my mobile device give that error:
Code
java.lang.RuntimeException: Unable to start receiver com.e1c.mobile.PushNotificationReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 pkg=com.e1c.mobile cmp=com.e1c.mobile/.PushNotificationService (has extras) }: app is in background uid UidRecord{b0a3730 u0a164 RCVR idle procs:1 seq(0,0,0)}
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3705)
at android.app.ActivityThread.-wrap18(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1979)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7425)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 pkg=com.e1c.mobile cmp=com.e1c.mobile/.PushNotificationService (has extras) }: app is in background uid UidRecord{b0a3730 u0a164 RCVR idle procs:1 seq(0,0,0)}
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1701)
at android.app.ContextImpl.startService(ContextImpl.java:1657)
at android.content.ContextWrapper.startService(ContextWrapper.java:644)
at android.content.ContextWrapper.startService(ContextWrapper.java:644)
at android.support.v4.content.WakefulBroadcastReceiver.a(Unknown Source:23)
at com.e1c.mobile.PushNotificationReceiver.onReceive(Unknown Source:19)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3695)
... 8 more
back you get an object of type "DeliverableNotificationSubscriberID". One of the properties of this object "SubscriberType" must be set to FCM, but 1C instead returns GCM.
As a result, you send the wrong SubscriberID value to the server and therefore an error occurs when sending push notifications.
We will fix this bug as quickly as possible in the next releases of the 1C platform.
Now I can offer you to generate SubscriberID on the server at the time of sending push notifications itself. To do this, change the value of "SubscriberType" from "GCM" to "FCM".
Hope the following code helps you figure out how to do this:
Code
Function DeSerialize(Data, ConversionType = Undefined)
XMLReader = New XMLReader;
XMLReader.SetString(Data);
mReadXML = XDTOSerializer.ReadXML(XMLReader, ConversionType);
XMLReader.Close();
Return mReadXML;
EndFunction
Function GetClientID()
Return DeSerialize(Constants.ClientID.Get()).DeviceID;
EndFunction
Function ReceiveRecipient()
DeviceID = GetClientID();
xdtoSubscriber = XDTOFactory.Create(XDTOFactory.Type("http://v8.1c.ru/8.3/data/ext","DeliverableNotificationSubscriberID"));
xdtoSubscriber.DeviceID = DeviceID;
xdtoSubscriber.SubscriberType = XDTOFactory.Create(XDTOFactory.Type("http://v8.1c.ru/8.3/data/ext","DeliverableNotificationSubscriberType"), "FCM");
NewSerializerXDTO = New XDTOSerializer(XDTOFactory);
Subscriber = NewSerializerXDTO.ReadXDTO(xdtoSubscriber);
Return Subscriber;
EndFunction
&AtClient
Procedure SendPush(Command)
ServerKey = "_YOUR_SERVER_KEY_";
Notification = New DeliverableNotification;
Notification.Title = "Some text";
Notification.Text = "Some text";
Notification.Data = "Some text";
Notification.SoundAlert = SoundAlert.Default;
Notification.Recipients.Add(ReceiveRecipient());
pErrors = New Array;
DeliverableNotificationSend.Send(Notification, ServerKey,,, pErrors);
If pErrors.Count() > 0 Then
Else
EndIf;
EndProcedure