From the course: iOS and watchOS App Development: Notifications

Launch a JSON payload

From the course: iOS and watchOS App Development: Notifications

Start my 1-month free trial

Launch a JSON payload

- [Instructor] We're ready to explore JSON payloads. From this point on, if you've not been following along with the exercises and you're downloading an exercise, please refer to the Using Exercise video in the introduction chapter for very important directions. You'll notice in apnstester, there's a selection for JSON. Click the JSON button, and the payload changes to this. For compactness, the wide space is removed. When sending payloads, avoid wide space for they are hard to read this way. It looks better with a few tabs and new lines. In Xcode, you'll find a file named HuliPizzaPayload.apns I made for you in the project. And I did exactly that, and got all those spaces all straightened up. You'll see that there's one top level key aps. Apple stores this required key your standard notification content. Aps is a dictionary. There's some standard keys within aps. The three we have in the sample do much of the work. The key alert posts a message in the body of a notification. The key badge sets a number on the icon badge. The sound plays a sound or vibration when the notification appears on the device. Under alert, change the message to I love pizza. Go ahead and copy and paste this code into apnstester. Add your pem file if you need it, and go ahead and hit TEST. You'll get your notification on your phone. This is, of course, a very simple example. The payload can get more sophisticated. I wanted to show you the structure before we work more with them. Make sure you have at least an aps key in every payload. These payloads should also remain small. They have a 4,096 byte limit, the equivalent of about 5 tweets. While we'll leave this payload with wide space so we can read it, in general use, avoid wide space to get the most out of that space.

Contents