Debian Codegraph @

docs/highlevel.txt

raw
1 Lomiri Push Service High Level Developer Guide
2 ==============================================
3
4 :Version: 0.100.3
5
6 .. contents::
7
8 Introduction
9 ------------
10
11 This document describes how to use the Ubuntu Push Client service from the point of view of a developer writing
12 a QML-based application.
13
14 ---------
15
16 .. include:: _description.txt
17
18 The PushClient Component
19 ------------------------
20
21 Example::
22
23 import Lomiri.PushNotifications 0.1
24
25 PushClient {
26 id: pushClient
27 Component.onCompleted: {
28 notificationsChanged.connect(messageList.handle_notifications)
29 error.connect(messageList.handle_error)
30 }
31 appId: "app.example_app"
32 }
33
34 Registration: the appId and token properties
35 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36
37 To register with the push system and start receiving notifications, set the
38 ``appId`` property to your application's APP_ID, with or without version number.
39
40 The APP_ID is as described in the `ApplicationId documentation <https://wiki.ubuntu.com/AppStore/Interfaces/ApplicationId>`__
41 except that the version is treated as optional. Therefore both ``app.example_app`` and ``app.example_app_1.3.496``
42 are valid. Keep in mind that while both versioned and unversioned APP_IDs are valid, they are still different and will affect
43 which notifications are delivered to the application. Unversioned IDs mean the token will be the same after updates and the application
44 will receive old notifications, while versioned IDs mean the app needs to explicitly ask to get older messages delivered.
45
46 Setting the same appId more than once has no effect.
47
48 After you are registered, if no error occurs, the PushClient will have a value set in its ``token`` property
49 which uniquely identifies the user+device combination.
50
51 Receiving Notifications
52 ~~~~~~~~~~~~~~~~~~~~~~~
53
54 When a notification is received by the Push Client, it will be delivered to your application's push helper, and then
55 placed in your application's mailbox. At that point, the PushClient will emit the ``notificationsChanged(QStringList)`` signal
56 containing your messages. You should probably connect to that signal and handle those messages.
57
58 Because of the application's lifecycle, there is no guarantee that it will be running when the signal is emitted. For that
59 reason, apps should check for pending notifications whenever they are activated or started. To do that, use the
60 ``getNotifications()`` slot. Triggering that slot will fetch notifications and trigger the
61 ``notificationsChanged(QStringList)`` signal.
62
63 Error Handling
64 ~~~~~~~~~~~~~~
65
66 Whenever PushClient suffers an error, it will emit the ``error(QString)`` signal with the error message.
67
68 Persistent Notification Management
69 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70
71 Some notifications are persistent, meaning that, after they are presented, they don't disappear automatically.
72 This API allows the app to manage that type of notifications.
73
74 On each notification there's an optional ``tag`` field, used for this purpose.
75
76 The ``persistent`` property of PushClient contains the list of the tags of notifications with the "persist" element set
77 to true that are visible to the user right now.
78
79 The ``void clearPersistent(QStringList tags)`` method clears persistent notifications for that app marked by ``tags``.
80 If no tag is given, match all.
81
82
83 The ``count`` property sets the counter in the application's icon to the given value.
84
85 .. include:: _common.txt