Add notification
into INSTALLED_APPS
in settings.py
file
INSTALLED_APPS += (
'notification',
)
Add notification
routing in urls.py
file
from django.conf.urls import include
urlpatterns += (
url(r'^ios/', include('notification.urls', namespace='notification')),
)
$ python manage.py migrate
$ python manage.py createsuperuser
$ python manage.py runserver
Please access http://127.0.0.1:8000/cert_upload and login by superuser, then upload push notification’s certificate.
Note
$ openssl pkcs12 -in hoge.p12 -out hoge.pem -nodes -clcerts
/receive
¶Send device token http://127.0.0.1:8000/receive with UUID.
Name | Type | Required | Note |
---|---|---|---|
device_token | String | YES | 64 letters |
uuid | String | YES | 36 letters |
sandbox | Bool | YES |
PUT
application/json
notification.models.DeviceToken
{"result": "success"}
{"error": "Bad Request"}
notification.models.DeviceToken
has user
field so you can also associate users by applying django.contrib.auth.models.User
.
$ curl -X PUT http://127.0.0.1:8000/receive \
-d '{"device_token": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "uuid": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", "sandbox": true}'
/send
¶It is possible to send a push notification easily.
Real route is /send/<TARGET_MODE>/<DEVICE_TOKEN>
.
0
1
http://127.0.0.1:8000/send/0/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX?message=test%20push%20notification
http://127.0.0.1:8000/send/1/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
/cert_upload
¶Upload push notifications’ certificates by superuser.
Note
/login
¶Login to session.
/logout
¶Logout from session.
Send a push notification to one device token.
$ cd /path/to/your_django_project/
$ python manage.py singlepush (--sandbox) \
--token XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \
--title Notification's\ title \
(--subtitle Notification's\ subtitle) \
(--body Notification's\ body) \
(--sound default) \
(--badge 1) \
(--contentavailable) \
(--mutablecontent) \
(--extra '{"key":"value","key2":"value2"}')
Argument name | Description | Required | Default |
---|---|---|---|
--sandbox , -s |
Use apple sandbox. | NO | False |
--token , -t |
Target device token. | YES | None |
--title |
Title displayed in push notification. | YES | None |
--subtitle |
Subtitle displayed in push notification. | NO | None |
--body |
Body displayed in push notification. | NO | None |
--sound |
Sounds to be heard when push notification is received. | NO | default |
--badge |
Badge displayed on application icon. | NO | 0 |
--contentavailable , -c |
Use content-available. (Support for iOS7 or higher) | NO | False |
--mutablecontent , -m |
Use mutable-content. (Support for iOS9 or higher) | NO | False |
--extra , -e |
Custom notification payload values as a JSON dictionary. | NO | None |
Send push notifications to some device tokens.
$ cd /path/to/your_django_project/
$ python manage.py multipush (--sandbox) \
-t XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY \
(--all) \
--title Notification's\ title \
(--subtitle Notification's\ subtitle) \
(--body Notification's\ body) \
(--sound default) \
(--badge 1) \
(--contentavailable) \
(--mutablecontent) \
(--extra '{"key":"value","key2":"value2"}')
Argument name | Description | Required | Default |
---|---|---|---|
--sandbox , -s |
Use apple sandbox. | NO | False |
--token , -t |
Target device token. | YES | None |
--all , -a |
Target all device tokens. | NO | False |
--title |
Title displayed in push notification. | YES | None |
--subtitle |
Subtitle displayed in push notification. | NO | None |
--body |
Body displayed in push notification. | NO | None |
--sound |
Sounds to be heard when push notification is received. | NO | default |
--badge |
Badge displayed on application icon. | NO | 0 |
--contentavailable , -c |
Use content-available. (Support for iOS7 or higher) | NO | False |
--mutablecontent , -m |
Use mutable-content. (Support for iOS9 or higher) | NO | False |
--extra , -e |
Custom notification payload values as a JSON dictionary. | NO | None |