Kodeco Forums

Push Notifications Tutorial: Getting Started

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!


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1270-push-notifications-tutorial-getting-started
1 Like

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

A few reasons actually.

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!

When the system language is set to Chinese, the date parser will go wrong. I think it’s something about locale?

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 ?

In this blog i came to know about the push notifications concept it is really nice and informative thanks for sharing this concept.

Thanks for reporting that, I’ll look into it. Very likely to have to do with the locale. If you already fixed it let me know :]

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.

Great tutorial, thanks.

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?

1 Like

Thank you, Jack, for great and handy tutorial.

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.

static func dateWithPodcastDateString(dateString: String) -> NSDate? {
    dateFormatter.locale = NSLocale(localeIdentifier: "en_US")
    dateFormatter.dateFormat = "EEE, dd, MMM yyyy HH:mm:ss Z"
    return dateFormatter.dateFromString(dateString)
}

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”

Maybe somebody, could clarify.

In my case, it is this delegate method that is called all the time.

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler

In which cases is the

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

supposed to be called?

Hi,
Does silent push notification work all the time?
Or only when the app is in background?
Thanks

Hi Jack,

Thank you for he fantastically detailed article!

I’m especially interested in a Silent Notification option, which we’d like to use in Wallet cards update, instead of for the application.

Is there any way a wallet card can be updated without disturbing the user with push notification?

Many thanks!

Thanks huralnyk.

I have same problem.
your patch works for me.

Thanks guys for all the feedback!

I’ll be updating the code in the next few days for full Swift 2.2 support as well as fix the locale bug that you guys found. :]

1 Like

Hi Jack!

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?

Thanks in advance
Zsolt

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.

Please provide the link for Previous Tutorial for apple push notification services in iOS 6 tutorial part 1

thank you

Can you tell me is there any way to handle notification when app was killed (removed from background).

I need to store some data into database and based on some validations I need to schedule a local notification.

In some forums they are saying , we can’t schedule a local notification when app in killed state.

Please respond to this.

Thanks.

1 Like

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.

Check out this tutorial: https://www.raywenderlich.com/126098/top-5-parse-alternatives. Also, there is an upcoming tutorial using Parse-server so stay tuned!

Sorry but this tutorial has replaced that one. If you have any specific questions, i can help you here!

As far as I know there isn’t anything you can do if the user has killed your app. Let me know if you find any workarounds!