PyAPNs2 icon indicating copy to clipboard operation
PyAPNs2 copied to clipboard

Provided examples do not work

Open ctoday1 opened this issue 1 year ago • 1 comments

from apns2.client import APNsClient from apns2.payload import Payload

token_hex = 'b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b87' payload = Payload(alert="Hello World!", sound="default", badge=1) topic = 'com.example.App' client = APNsClient('key.pem', use_sandbox=False, use_alternative_port=False) client.send_notification(token_hex, payload, topic)

To send multiple notifications in a batch Notification = collections.namedtuple('Notification', ['token', 'payload']) notifications = [Notification(payload=payload, token=token_hex)] client.send_notification_batch(notifications=notifications, topic=topic)

To use token based authentication from apns2.credentials import TokenCredentials

auth_key_path = 'path/to/auth_key' auth_key_id = 'app_auth_key_id' team_id = 'app_team_id' token_credentials = TokenCredentials(auth_key_path=auth_key_path, auth_key_id=auth_key_id, team_id=team_id) client = APNsClient(credentials=token_credentials, use_sandbox=False) client.send_notification_batch(notifications=notifications, topic=topic)

  • On the first example "key.pem" is a placeholder and not described in the documentation.
  • On the second example "collections" is not imported or declared, and also not documented as to what it is.
  • On the third example there's a bunch that is undeclared. Even after piecing it together from the previous examples, the "collections" item is still undeclared(and undocumented)

ctoday1 avatar Feb 10 '24 21:02 ctoday1

  1. key.pem stands for a certificate-file provided by Apple to use their push-notification service. You can generate / download that from your Apple Developer Account. For more details, go to this Apple-documentation
  2. The collections-import is simply missing from the code-snippet. Add the line import collections at the top of the snippet.
  3. I did not use the token-based authentication method for the APNs. For details, refer to this page. The collections-issue should be resolved with answer 2.

Please take notice, that this library seems to not be in active development anymore. Especially, it fails to work correctly starting with Python 3.10, for details see the other currently open issues, which refer to the dependency hyper not being compatible with Python 3.10 and Python 3.11.

As I am currently working on an implementation based on the current library httpx and first tests look usable, I might be able to support a forked modernized version of this library in my namespace soon.

ajans avatar Feb 12 '24 16:02 ajans

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

github-actions[bot] avatar Aug 13 '24 00:08 github-actions[bot]