In this push notifications tutorial you'll learn how to use to notify your users, and perform small tasks even when they aren’t actively using your app!
dear jack
can i ask why you choose to use a outside server instead of using CloudKit to send the messages ?
i would think its cheaper to just use CloudKit
and i know its possible to send push notifications from CloudKit, i tried it
First of all this article isn’t about the server side, and the script provided is just meant for testing that the notifications work. The focus is on the iOS app’s side and what you need to do to receive and handle different kinds of notifications. There are many ways you could implement the server-component of an iOS app and there probably needs to be a tutorial here that covers that. :]
Secondly, as far as I know, CloudKit doesn’t send general push notifications. You can “subscribe” to certain changes in the database and it will send a content-available silent push notification when needed. Due to this, it wouldn’t serve the purpose of a general push notification server and also would be quite difficult to help test our push notifications in this tutorial!
Hi, Jack
I have question about silent push notifications… I read that if user manualy killed the app (app switcher for example) the delegate method wont be called. Do you know something about that ?
You are correct and this is stated in the documentation:
However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.
How can we send a notification to a specific device? Do we have to save all the app-id’s on the server and then decide choose a specific app-id to send notification to it?
Or there’s any other better way to achieve this?
Application crashes on me with different sets of Language and Region settings (ex. Russian:Ukraine, English:United States, Russian:United States). Just hardcode locale of dateFormatter to en_US worked for me.
But anyway it’s a bit strange and unclear to me why we use exact this date format with two commas "EEE, dd, MMM yyyy HH:mm:ss Z", when our date string looks like this: “Wed, 04 Nov 2015 21:00:14 +0000”
First of all, many thanks for the great tutorial.
Do you have any idea about what should I do, if I’d like to perform some tasks in the background, but don’t want the notification to be silent? I want to send to the server something like an ACK, that the message was arrived, but I also want the user to be notified at the same time.
Do you have any solution for that?
I am newbie developer. I need some real help. I currently use Parse.com for Push Notifications for one app. I am a master with using that system. I know how to configure and send push notifications with it. I followed their documentation to the letter. I now need to send specific notifications. the way it works right now all users get the notification I send out no matter what. I want the user to choose to receive certain notifications. Like all news, breaking news, top stories, etc. I am unclear on how to do so. I anyone know of a guide that shows this kindly email me at timbojill@gmail.com.
I know Parse.com is closing down soon. If someone has a guide or know how to do it with Parse.com let me know. Someone was telling me that Pushwoosh does it but I couldn’t figure it out.
Thanks for all your feedback and even help with fixing this project! The starter project has been updated to address all the NSDateFormatter related issues as well as support for Swift 2.2.
To answer some specific questions in the thread here:
The Device Token represents the “address” of a single device. If you were to build your backend yourself, you must save all device tokens in your database. Generally you would associate it with a specific user so that your server will know which device(s) to send to when it needs to send a notification. Again, there are many services and frameworks that can do this for you.
The 2nd method here would only be called if the first one is not implemented. Quote from Apple documentation:
Implement the application:didReceiveRemoteNotification:fetchCompletionHandler: method instead of this one whenever possible. If your delegate implements both methods, the app object calls the application:didReceiveRemoteNotification:fetchCompletionHandler: method.
These should work all the time, unless the user “swipes up” and kills your app.
When your app receives the silent notification, you get a chance to run any code you want. You can send a request back to your server and also schedule a local, non-silent notification that your user can see. Just keep in mind that any time you spend here counts towards your “quota” and your background time may be limited by the system if you run too often or take too long.