# Push Notifications Tutorial: Getting Started

**URL:** <https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056>\
**Category:** 🎓 Courses & Articles\
**Created:** [March 17, 2016, 1:12pm UTC](https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056 "2016-03-17T13:12:17Z")\
**Posts on this page:** 20\
**Page:** 4

<div class="post-metadata">

**Author:** ![tobitech](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/tobitech/32/108673_2.png) [@tobitech](https://forums.kodeco.com/u/tobitech)\
**Post date:** [June 27, 2016, 9:38am UTC](https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056/62 "2016-06-27T09:38:15Z")

</div>

Please Can I get the Objective-C version of this tutorial or the previous versions of the article

---

<div class="post-metadata">

**Author:** ![mikekh](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/mikekh/32/36308_2.png) [@mikekh](https://forums.kodeco.com/u/mikekh)\
**Post date:** [July 5, 2016, 2:51pm UTC](https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056/63 "2016-07-05T14:51:09Z")

</div>

Hi Jack  
Nice tutorial! how can i push notifications from an online website of mine?

---

<div class="post-metadata">

**Author:** ![manuwiseman](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/manuwiseman/32/37047_2.png) [@manuwiseman](https://forums.kodeco.com/u/manuwiseman)\
**Post date:** [July 15, 2016, 8:12pm UTC](https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056/64 "2016-07-15T20:12:50Z")

</div>

Absolutely awesome man, great great tutorial.

I used AWS SNS as my Push Notification Service, one thing to point out to everyone (probably many have figured out) is :  
If you created your Apple developer app and APNS certificate in the development environment, you will want to set APNS\_SANDBOX as your platform to push the notification to.

---

<div class="post-metadata">

**Author:** ![manuwiseman](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/manuwiseman/32/37047_2.png) [@manuwiseman](https://forums.kodeco.com/u/manuwiseman)\
**Post date:** [July 15, 2016, 8:14pm UTC](https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056/65 "2016-07-15T20:14:38Z")

</div>

Did you try delete the app on the device and re-run the project?

---

<div class="post-metadata">

**Author:** ![manuwiseman](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/manuwiseman/32/37047_2.png) [@manuwiseman](https://forums.kodeco.com/u/manuwiseman)\
**Post date:** [July 15, 2016, 8:17pm UTC](https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056/66 "2016-07-15T20:17:22Z")

</div>

take Amazon SNS as an example: [Mobile push notifications - Amazon Simple Notification Service](http://docs.aws.amazon.com/sns/latest/dg/mobile-push-apns.html)  
you can download their sample code, use the AmazonSNSClientWrapper class in the codebase of your website code and then push notification to your ios app.

---

<div class="post-metadata">

**Author:** ![hermannk](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/hermannk/32/37702_2.png) [@hermannk](https://forums.kodeco.com/u/hermannk)\
**Post date:** [July 26, 2016, 10:30am UTC](https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056/67 "2016-07-26T10:30:11Z")

</div>

Hi, thanks for the great tutorial! I have a question though which seems to deal with quite a specific problem and which I am trouble finding any advice for. My question regards the background fetching of data once a silent notification is received. First of all, for background modes for the app, do we only need to enable push notifications or background fetch as well? When I’ve tested so far, the app does get into the “didreceiveremotenotification” method fine, however the processing inside that method just seem to stop, but that app doesn’t freeze, so I don’t know if the OS is impeding my app from doing background work. What I am trying to do is download messages from a server in the background, but to do that I am simply calling a function that authenticates with the server because the messages will download automatically when we are authenticated. All of this functionality happens in a different class and I am logging a lot of information so that I can see where the pause occurs. So I am calling the authenticate function from the “didreceiveremotenotification” method, but the all the processing and stuff happens in a different class. At some point I send a notification for which the AppDelegate is listening and then it’s supposed to call completionhandler. For some reason I am not getting very far into the process before the processing stops. If I put a sleep command, I do get further sometimes and I even get to the completiong handler sometimes, but not all the time. I am just wondering if you could please help me understand the situation. Do we need to do all the work inside the “didreceiveremotenotification” method? I doubt that. Can we call the completionhandler when a notification is received. I assume so, but I am missing something I think.

Any help would be much appreciated!

Regards,

Hermann Kuschke

---

<div class="post-metadata">

**Author:** ![alaasabra](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/alaasabra/32/38881_2.png) [@alaasabra](https://forums.kodeco.com/u/alaasabra)\
**Post date:** [August 14, 2016, 11:04pm UTC](https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056/69 "2016-08-14T23:04:14Z")

</div>

I tried a lot with this problem but without any result I searched a lot and I’m sure from everything about permission,port number and certificate but this error is appear to me at all time

Warning: stream\_socket\_client(): SSL: Connection reset by peer in /Users/alaa/Desktop/WenderCast-Starter/WenderCastPush/newspush.php on line 24

Warning: stream\_socket\_client(): Failed to enable crypto in /Users/alaa/Desktop/WenderCast-Starter/WenderCastPush/newspush.php on line 24

Warning: stream\_socket\_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /Users/alaa/Desktop/WenderCast-Starter/WenderCastPush/newspush.php on line 24  
Failed to connect: 0

How I can solve that, please 😔

---

<div class="post-metadata">

**Author:** ![arvindgr](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/arvindgr/32/39585_2.png) [@arvindgr](https://forums.kodeco.com/u/arvindgr)\
**Post date:** [August 24, 2016, 9:42am UTC](https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056/70 "2016-08-24T09:42:42Z")

</div>

Hey Developers, It is always difficult and time consuming to test push notification and its redirection with web team. As an iOS Developer I wanted this to be under my control so that I can test whenever needed. To help other developers and freelancers I have created a simple web app in my free time to test Push Notifications (APNS) and Google Cloud Messaging (GCM). Check it out [http://www.pushtry.com](http://www.pushtry.com)

---

<div class="post-metadata">

**Author:** ![ashok9990](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/ashok9990/32/81494_2.png) [@ashok9990](https://forums.kodeco.com/u/ashok9990)\
**Post date:** [September 2, 2016, 6:29am UTC](https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056/71 "2016-09-02T06:29:32Z")

</div>

hi Jack,

Nice tutorail,

Please tell me it is possible send image using APNS?

if it is possible then how can send it using in ios.

Thanks!

---

<div class="post-metadata">

**Author:** ![knokio](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@knokio](https://forums.kodeco.com/u/knokio)\
**Post date:** [October 2, 2016, 9:06pm UTC](https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056/72 "2016-10-02T21:06:41Z")

</div>

I am getting this error as well. Did you resolve it?

---

<div class="post-metadata">

**Author:** ![knokio](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@knokio](https://forums.kodeco.com/u/knokio)\
**Post date:** [October 3, 2016, 1:58am UTC](https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056/73 "2016-10-03T01:58:24Z")

</div>

Jack\_Wu…anybody. I just started this tutorial yesterday and I have done it over a ton of times and I get the same results. The last post of this forum was my inquiry from Alaaa’s entry…same exact issue. I’ve used apn tester and can send notifications via that tool but I can not get the php script to do it. Please help.

---

<div class="post-metadata">

**Author:** ![jphilippou](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jphilippou/32/43482_2.png) [@jphilippou](https://forums.kodeco.com/u/jphilippou)\
**Post date:** [October 6, 2016, 12:16am UTC](https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056/74 "2016-10-06T00:16:47Z")

</div>

I struggled with this. I was getting the following:

Warning: stream\_socket\_client(): SSL operation failed with code 1. OpenSSL Error messages:  
error:14090086:SSL routines:SSL3\_GET\_SERVER\_CERTIFICATE:certificate verify failed…

At some point in my searching the Internet I ran across the following suggestion – add this line of code:

stream\_context\_set\_option($ctx, ‘ssl’, ‘verify\_peer’, false);

This worked, but it deletes the purpose of SSL because it disables the script from verifying that it is talking with APNS. I didn’t want that as my long term solution, So I kept searching and ran across this post:

[[ios - Push Notification in PHP using PEM file - Stack Overflow](http://stackoverflow.com/questions/28221224/push-notification-in-php-using-pem-file)]

Sandy D.'s solution worked great!

---

<div class="post-metadata">

**Author:** ![saketgupte](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/saketgupte/32/43594_2.png) [@saketgupte](https://forums.kodeco.com/u/saketgupte)\
**Post date:** [October 7, 2016, 7:24am UTC](https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056/75 "2016-10-07T07:24:14Z")

</div>

Hey Jack,

Thanks for the wonderful tutorial. It was very helpful indeed.  
However, I have a different kind of problem when handling push notification. In my project, we have a number of view controllers which we need to display depending on the type of data received in the notification. For this, we have created a class which parses the data and has a switch case to which initializes the controller from the push notification and pushes it on the stack. But the switch case causes the app to be very brittle. A small change here or there and the push stop working and has lately become highly unmaintainable. I was wondering if you had a cleaner way to handle this kind of scenario.

---

<div class="post-metadata">

**Author:** ![rokridi](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rokridi/32/43626_2.png) [@rokridi](https://forums.kodeco.com/u/rokridi)\
**Post date:** [October 7, 2016, 1:43pm UTC](https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056/76 "2016-10-07T13:43:41Z")

</div>

I advise you to use this great tool that allows to send Push Notifications : [NWPusher](https://github.com/noodlewerk/NWPusher)

---

<div class="post-metadata">

**Author:** ![rokridi](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rokridi/32/43626_2.png) [@rokridi](https://forums.kodeco.com/u/rokridi)\
**Post date:** [October 7, 2016, 1:46pm UTC](https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056/77 "2016-10-07T13:46:18Z")

</div>

You can but keep in mind that the payload size is limited to 2 kilobytes. I suggest you send the link to the image in the push notification’s payload then you download it when you should respond to the push notification.

---

<div class="post-metadata">

**Author:** ![adammendoza](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/adammendoza/32/41911_2.png) [@adammendoza](https://forums.kodeco.com/u/adammendoza)\
**Post date:** [October 11, 2016, 2:50am UTC](https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056/78 "2016-10-11T02:50:40Z")

</div>

Would it be possible to get the user’s location in a silent alert and send that location to the server?  
I’m sending a notification with “content-available”: 1 and starting a location manager but the locationManager:(CLLocationManager \*)manager didUpdateLocations: does not get called in the back ground. I’m trying to avoid tracking location constantly by requesting it only when it’s needed via a push notification.

---

<div class="post-metadata">

**Author:** ![chamathjeevan](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/chamathjeevan/32/47662_2.png) [@chamathjeevan](https://forums.kodeco.com/u/chamathjeevan)\
**Post date:** [November 4, 2016, 10:41am UTC](https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056/79 "2016-11-04T10:41:23Z")

</div>

Please use the following command to build the .pem file .

openssl pkcs12 -in M8CardPushProd.p12 -out ckp.pem -nodes -clcerts

Also do not for get to add the php code line below to your php push test file.  
stream\_context\_set\_option($ctx, ‘ssl’, ‘verify\_peer’, false);

---

<div class="post-metadata">

**Author:** ![johnhubler](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/johnhubler/32/47451_2.png) [@johnhubler](https://forums.kodeco.com/u/johnhubler)\
**Post date:** [November 13, 2016, 2:27am UTC](https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056/80 "2016-11-13T02:27:29Z")

</div>

Any chance you’ll be updating this for Swift 3 anytime soon?

---

<div class="post-metadata">

**Author:** ![woody121](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/woody121/32/47794_2.png) [@woody121](https://forums.kodeco.com/u/woody121)\
**Post date:** [November 16, 2016, 4:28am UTC](https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056/81 "2016-11-16T04:28:26Z")

</div>

ATTENTION MAC SIERRA USERS:  
You will not be able to complete this tutorial unless you head the (currently second to top) answer on stack: [ios - APNs push notification with macOS Sierra - Stack Overflow](http://stackoverflow.com/questions/39612022/apns-push-notification-with-macos-sierra)

Basically Sierra updated php to 2.6, so you must replaced:

` $streamContext = stream_context_create();`

with:

```
$streamContext = stream_context_create([
            'ssl' => [
                'verify_peer' => false,
                'verify_peer_name' => false
            ]
        ]);

```

or else you get this error:

```
Warning: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in /Users/USERNAME/APNS/newPush.php on line 24

Warning: stream_socket_client(): Failed to enable crypto in /Users/USERNAME APNS/newPush.php on line 24

Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /Users/USERNAME/APNS/newPush.php on line 24
Failed to connect: 0

```

---

<div class="post-metadata">

**Author:** ![zodor](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/zodor/32/48035_2.png) [@zodor](https://forums.kodeco.com/u/zodor)\
**Post date:** [November 17, 2016, 8:04pm UTC](https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056/82 "2016-11-17T20:04:32Z")

</div>

Your solution worked like a charm.  
Great !!! Thanks !!!

[Previous page](https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056.md?page=3)

[Next page](https://forums.kodeco.com/t/push-notifications-tutorial-getting-started/10056.md?page=5)
