Ivan219
Posts: 118
Joined: Sun Jul 05, 2015 10:01 pm

Send notifications from raspberry pi to ios-devices

Wed Jan 27, 2016 9:46 pm

Hello, I want to send notifications from raspberry pi python to ios-devices. I make a simple app in Xcode and get token of my device. Then I install apnsclient to python3 on my raspberry pi. And write code:

Code: Select all

from apnsclient import *

# For feedback or non-intensive messaging
con = Session().new_connection("feedback_sandbox", cert_file="apns.pem")
# New message to 3 devices. You app will show badge 10 over app's icon.
message = Message(["my_token"], alert="My message", badge=10)

# Send the message.
srv = APNs(con)
try:
    res = srv.send(message)
except:
    print ("Can't connect to APNs, looks like network is down")
else:
    # Check failures. Check codes in APNs reference docs.
    for token, reason in res.failed.items():
        code, errmsg = reason
        # according to APNs protocol the token reported here
        # is garbage (invalid or empty), stop using and remove it.
        print ("Device failed: {0}, reason: {1}".format(token, errmsg))

    # Check failures not related to devices.
    for code, errmsg in res.errors:
        print ("Error: {}".format(errmsg))

    # Check if there are tokens that can be retried
    if res.needs_retry():
        # repeat with retry_message or reschedule your task
        retry_message = res.retry()
When I start script I get message:
from apnsclient import *
ImportError: No module named apnsclient
How resolve problem?

User avatar
topguy
Posts: 6527
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Send notifications from raspberry pi to ios-devices

Wed Jan 27, 2016 10:59 pm

- How exactly did you install "apnsclient" ?
- You are sure that you are running Python3 ?

Ivan219
Posts: 118
Joined: Sun Jul 05, 2015 10:01 pm

Re: Send notifications from raspberry pi to ios-devices

Thu Jan 28, 2016 7:57 am

Thank for your reply!) I Use:
sudo easy_install3 apnsclient
Yes, I am sure that I use python 3.2. Previously, such problems were not. May be It could use another module?

User avatar
AiGreek
Posts: 229
Joined: Sun Dec 06, 2015 7:44 pm

Re: Send notifications from raspberry pi to ios-devices

Thu Jan 28, 2016 8:01 am

I'm starting to think I always say the same things,
but why you just use Pushbullet ?
It's compatible Windows/Mac, Android/iOS and there is a **** great lib for Python (Python 2) and it's so much easier.

Ivan219
Posts: 118
Joined: Sun Jul 05, 2015 10:01 pm

Re: Send notifications from raspberry pi to ios-devices

Thu Jan 28, 2016 8:07 am

PushBullet a good solution, but it does not fit me, because I am in the future want to send notifications to my application via vps, and now i am testing it on my raspberry pi.

Ivan219
Posts: 118
Joined: Sun Jul 05, 2015 10:01 pm

Re: Send notifications from raspberry pi to ios-devices

Thu Jan 28, 2016 10:17 am

Install django-push and get error:
from django.conf import settings
ImportError: No module named django.conf

mgsteinkamp
Posts: 1
Joined: Thu Sep 14, 2017 2:22 am

Re: Send notifications from raspberry pi to ios-devices

Thu Sep 14, 2017 2:48 am

Hi guys,

Pretty late here, but since I also had the same problem I thought I'd post the solution

I also installed via pip/pip3 which installed
apnsclient-0.1.tar.gz
However, the install was no good. It's missing most of the necessary files, so I manually installed apnsclent from
apnsclient-0.2.1.tar.gz
(available here).


Hope this helps!

Return to “Beginners”