Group Group Group Group Group Group Group Group Group

Push Notifications Tutorial: Getting Started | raywenderlich.com

Push notifications allow developers to reach users, even when users aren’t actively using an app! In this tutorial, you’ll learn how to configure your app to receive push notifications and to display them to your users or perform other tasks.


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

How do I handle View Action without opening the app? Is there way to do that?

Could you elaborate a bit on what you are trying to do? I’d be happy to try and offer some guidance.

I want the user to complete a task from the push notification without going into the app.
I followed your tutorial and added a category and an action identifier. When I run the app and trigger push notification( when the app is in the background ), the force touch brings up the “complete task” button. If I click on it, it opens the app. Is there a way I can complete the task without taking user into the app?

I think what you are looking for is described in this tutorial on our site: Rich Push Notifications. Check out the section on adding service extensions. It should give you some ideas.

I was working thru this tutorial and I believe there may be a slight mistake in the format of push notifications. Specifically, this sample notification with the custom field link_url -

{
  "aps": {
    "alert": "Breaking News!",
    "sound": "default",
    "link_url": "https://raywenderlich.com"
  }
}

In this example, link_url is part of “aps”, but according to the Apple docs the message should be formatted this way, with link_url as part of the main json object -

{
  "aps": {
    "alert": "Breaking News!",
    "sound": "default"
  },
  "link_url": "https://raywenderlich.com"
}

This is the link I was reading, and in the sample notification “gameID” is the custom field.
https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification#2943361

Here is the sample notification from the Apple docs -

{
   "aps" : {
      "alert" : {
         "title" : "Game Request",
         "subtitle" : "Five Card Draw",
         "body" : "Bob wants to play poker"
      },
      "category" : "GAME_INVITATION"
   },
   "gameID" : "12345678"
}

Thank you for pointing that out. You are correct. The Apple documentation specifically says, " Add app-specific keys as peers of the aps dictionary." I have embedded a correction in the tutorial and we will update the tutorial appropriately when we next update. As you probably noticed, it still works even when placed as a member of the aps dictionary, but we always suggest doing things in accordance with Apple’s documentation. Nice catch!

1 Like

I have a confusion, when we request authorisation why self?.getNotificationSettings() is needed? cant we just simply call UIApplication.shared.registerForRemoteNotifications() there itself.
I mean even if user turns off notifications, value of granted will be false and registerForRemoteNotifications will not be called.
What is the use of getting notification settings? Someone please help me there
thanks

As with many things in programming, there are various ways to accomplish the same thing. This tutorial is showing just one approach.