91.201.2
by Roberto Alsina
deduplicate, add Makefile |
1 |
Ubuntu Push Client High Level Developer Guide |
91.208.1
by Roberto Alsina
minor fix |
2 |
============================================= |
91.168.1
by Roberto Alsina
initial version of the QML-based documentation |
3 |
|
4 |
:Version: 0.50+ |
|
5 |
||
91.197.1
by Roberto Alsina
improved doc |
6 |
.. contents:: |
7 |
||
91.168.1
by Roberto Alsina
initial version of the QML-based documentation |
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 |
||
91.201.2
by Roberto Alsina
deduplicate, add Makefile |
16 |
.. include:: _description.txt |
91.168.1
by Roberto Alsina
initial version of the QML-based documentation |
17 |
|
18 |
The PushClient Component |
|
19 |
------------------------ |
|
20 |
||
21 |
Example:: |
|
22 |
||
91.168.2
by Roberto Alsina
indent |
23 |
import Ubuntu.PushNotifications 0.1 |
91.168.1
by Roberto Alsina
initial version of the QML-based documentation |
24 |
|
25 |
PushClient { |
|
26 |
id: pushClient |
|
27 |
Component.onCompleted: { |
|
91.199.5
by Roberto Alsina
signal got renamed, adjust the docs |
28 |
notificationsChanged.connect(messageList.handle_notifications) |
91.168.1
by Roberto Alsina
initial version of the QML-based documentation |
29 |
error.connect(messageList.handle_error) |
30 |
} |
|
31 |
appId: "com.ubuntu.developer.push.hello_hello" |
|
32 |
} |
|
33 |
||
34 |
Registration: the appId and token properties |
|
35 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
36 |
||
37 |
To register with the push system and start receiving notifications, set the ``appId`` property to your application's APP_ID, |
|
38 |
with or without version number. For this to succeed the user **must** have an Ubuntu One account configured in the device. |
|
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 ``com.ubuntu.music_music`` and ``com.ubuntu.music_music_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 |
|
91.199.5
by Roberto Alsina
signal got renamed, adjust the docs |
55 |
placed in your application's mailbox. At that point, the PushClient will emit the ``notificationsChanged(QStringList)`` signal |
91.168.1
by Roberto Alsina
initial version of the QML-based documentation |
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 |
|
91.199.5
by Roberto Alsina
signal got renamed, adjust the docs |
61 |
``notificationsChanged(QStringList)`` signal. |
91.168.1
by Roberto Alsina
initial version of the QML-based documentation |
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 |
||
91.197.4
by Roberto Alsina
rewording |
71 |
Some notifications are persistent, meaning that, after they are presented, they don't disappear automatically. |
91.199.4
by Roberto Alsina
removed mistery stuff |
72 |
This API allows the app to manage that type of notifications. |
91.168.1
by Roberto Alsina
initial version of the QML-based documentation |
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 |
||
91.168.5
by Roberto Alsina
new count property |
83 |
The ``count`` property sets the counter in the application's icon to the given value. |
91.168.1
by Roberto Alsina
initial version of the QML-based documentation |
84 |
|
91.208.1
by Roberto Alsina
minor fix |
85 |
.. include:: _common.txt |