43

In my application I am implementing the Push Notification Service.
I have a Content Provider server, which contains some products in it.
I have generated the SSL Client Certificate and attached it to my development Provisioning profile. This profile is also added to my application.
I have written the code inside the delegate methods (guided by Apple guideline for implementing the Push Notification). All set.

Now I want to test my application whether it is handing the push notification as per the requirement. Any idea on how can I test it would help me a lot.
Should I have to add new product to the content provider server to test this?

If yes, how much will APNS take to send the push notification to my device?

Tobi Nary
  • 4,566
  • 4
  • 30
  • 50
Naved
  • 4,020
  • 4
  • 31
  • 45

11 Answers11

64

I tried all 3 of the above suggestions with no success. In case someone else is ends up here looking for a solution to this, I found this and it works great:

Pusher https://github.com/noodlewerk/NWPusher

LunaCodeGirl
  • 5,432
  • 6
  • 30
  • 36
25

Very cool guide is posted here: Programming Apple Push Notification Services

And an application named PushMeBaby Mac Os App which you can download and use for sending push-notifications to your devices from a Mac.

APNS will send the push notification to your device as soon as your device will become available. If I've not mistaken your device pings APNS every minute.

rptwsthi
  • 10,094
  • 10
  • 68
  • 109
Nekto
  • 17,837
  • 1
  • 55
  • 65
  • I am running PushMeBaby application, but it does not load the certificate causing not to send any push notification. I have added that certificate as guided in the tutorial, but still it is not working. any idea? Is the certificate for sandbox or production? – Naved Sep 09 '11 at 13:35
  • 2
    As is said in tutorial - you should use for sandbox and input your device token in PushMyBaby. – Nekto Sep 09 '11 at 13:39
  • 1
    I did it so. I have added the certificate in resources using "Copy items into destination group folders" too. but still it is not working – Naved Sep 09 '11 at 13:42
  • 1
    Solved: Mine certificate name was "aps_developer_identity-1.cer" and not "aps.developer.identity-1.cer". Thank you for your support. – Naved Sep 09 '11 at 14:01
  • This app worked for me. https://itunes.apple.com/us/app/easy-apns-provider-push-notification/id989622350?mt=12 – Viral Narshana Dec 21 '16 at 14:02
  • link to "PushMeBaby Mac Os App" is dead – jeet.chanchawat Jul 01 '19 at 06:01
14

What about curl:

curl -d '{"aps":{"alert":"This is a test notification"}}' --cert YourCertificate.pem:YourPassword -H "apns-topic: com.example.yourapp" --http2  https://api.development.push.apple.com/3/device/YourDeviceToken

First you need curl with http2 support.
And you need to convert your push certificate to pem format using openssl.

erkanyildiz
  • 13,044
  • 6
  • 50
  • 73
14

If you want to support both Certificate and Token based authentication with APNS, then you can try Push Notifications

enter image description here

onmyway133
  • 45,645
  • 31
  • 257
  • 263
  • This should be marked as the right answer. The app is soo cool. I was afraid I had to use node-apn, so I have to spend one day more debugging. – Augusto Gonzalez Feb 05 '19 at 03:29
6

You should try the the branch of PushMeBaby, it worked for me.

Jagat Dave
  • 1,643
  • 3
  • 23
  • 30
Helge Staedtler
  • 101
  • 1
  • 4
4

Try this online application, through which you could paste in your device token and provide the certificate, and so send push notification to any devices and lets you customize the data as well. http://pushmebaby.herokuapp.com

2

You can use APNS tester,its a very good tool for test APNS from Mac Machine link to download this software. 2 things you need to provide to test push notification

1.APNS certificate (.cer file) 2.Device token of user's iOS device

Jagat Dave
  • 1,643
  • 3
  • 23
  • 30
Tarun Seera
  • 4,212
  • 4
  • 27
  • 41
1

PushMeBaby is frozen when I test iOS10 in Xcode8. Try NWPusher, https://github.com/noodlewerk/NWPusher. A friendly and simple tool with GUI.

Victor Choy
  • 4,006
  • 28
  • 35
0

If you google you will see a number of websites that do this. I usually use https://www.apnstester.com and https://www.pushty.com

nupadhyaya
  • 1,909
  • 1
  • 14
  • 14
0

I created a small script to do that

import json
import jwt
import time

from hyper import HTTPConnection

ALGORITHM = 'ES256'

# fill these items
APNS_KEY_ID = ''
TEAM_ID = ''
BUNDLE_ID = ''

# put path to p8 file
APNS_AUTH_KEY = ''

# put device token id (of the notification receiver)
REGISTRATION_ID = ''

# let's do the magic :)
f = open(APNS_AUTH_KEY)
secret = f.read()

token = jwt.encode(
    {
        'iss': TEAM_ID,
        'iat': time.time()
    },
    secret,
    algorithm= ALGORITHM,
    headers={
       'alg': ALGORITHM,
        'kid': APNS_KEY_ID,
   }
)

path = '/3/device/{0}'.format(REGISTRATION_ID)

equest_headers = {
'apns-expiration': '0',
'apns-priority': '10',
'apns-topic': BUNDLE_ID,
'authorization': 'bearer {0}'.format(token.decode('ascii'))
}

connection = HTTPConnection('api.development.push.apple.com:443')

# put the payload you need
payload_data = {
'aps': {
 'content-available': '1',
 },
}
payload = json.dumps(payload_data).encode('utf-8')

connection.request(
'POST',
path,
payload,
headers=request_headers
)
resp = connection.get_response()

print(resp.status)
print(resp.read())

https://gist.github.com/IvanivOleg/7ba4072128b2c05a068a6826be68a3d3

Oleshko
  • 2,923
  • 4
  • 17
  • 25
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – double-beep Feb 05 '19 at 17:31
0

Use terminal to test push notification with single line command

Install Houston in your Mac, run below command in terminal.

  1. gem install houston

    If you are facing error like this,

    Fetching houston-2.4.0.gem ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

    First run below commands in terminal to install Ruby

    brew install ruby

    export GEM_HOME="$HOME/.gem"

    gem install rails

    after successful installation run again

    gem install houston

  2. Go to the pem files folder and open terminal from that folder.

  3. Run below command like

    apn push "Device Token" -c PEM_FILE_NAME -m "MESSAGE"

    Like:

    apn push "5a4b74d5e5fc325b14d2f2641aa11bfb9744d1f88922822a5ed3512376d5f5b9" -c myapp_apns_dev.pem -m "Testing"

after successful run of above command it will ask for PEM pass phrase which is password of your pem file.

If your app is lived then use production pem file name

like this,

apn push "5a4b74d5e5fc325b14d2f2641aa11bfb9744d1f88922822a5ed3512376d5f5b9" -c myapp_apns_pro.pem -m "Testing"

Done.

Dhruvin Thumar
  • 190
  • 2
  • 10