You Drove It Out

Poetry of love and pain. “You Drove It Out” is written by America Zed and published by Share The Love on Medium.

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




iOS rich push notifications with media attachments

iOS 10 brings us push notifications that have new functionality compared to the ones in older operating system versions. Improvements include viewing photos, videos or gifs, right there, within the notification.

Having these media attachments as part of your notification is achieved with the use of the new Notification Service Extension. You can also have richer view controller level content within the media attachment view of the notification with the use of the, also new, Notification Content Extension. We’ll go through some code just below.

Make sure you have:

The apple push notification service sends remote notifications for your apps to each user’s device. A notification and a device token are sent the the APNS servers. In turn, they handle the routing of that notification to the correct user device. At that point, iOS takes over and makes sure the notification is delivered to your app. Push notifications have a maximum payload size of 4KB and they support development & production environments.

In order for you Notification Extension code to be executed the push notifications payload must be modified slightly (compared to iOS 9 for instance).

The media-url key contains the url of your media attachment which you’ll be using in your code. The payload also tells iOS which notifications will cause your Notification Extension to run by including the mutable-content with a value of 1. The time you have to execute your code is limited and as far as I can tell it’s several seconds which is an adequate amount of time to download an image.

**Update**: You can now easily test your push notifications on your devices with this simple command line tool I wrote. More information here.

Create a new target and add it to your project.

In short, to display an image in your push notification you have to

Before we get there though there are several things we have to do first. Initially, we have to register to receive push notifications in our app.

Next, we have to obtain the device token.

In case of an error.

And in the case you would like to know which permissions have been granted, you can:

All of the above can be in your applications delegate.

In the following code, we are locating the value for the key media-url. If it exists, we download the image from the URL which is the key’s value.

The URLSession downloads the media to temporary storage using a FileManager.

Create a new target and add it to your project.

Add a comment

Related posts:

ROLLING VENGEANCE Rumbles Its Way onto Blu

What does a man do when the drunken asshole sons of a powerful redneck in town recklessly take the lives of his mother, sister, and brother, rape his girlfriend, then kill his father in cold blood…

How to Enhance Business Communication

Small businesses have to overcome many obstacles on their path to transform into bigger organizations. However, in this digital age, you can conquer these obstacles by using technology. Technology…

Mustan laatikon ongelma

Autosta on polttoaine lopussa. Onneksi lähimmälle huoltoasemalle on matkaa vain muutama kilometri. GPS ohjaa tosin kääntymään pois valtaväylältä. Tasainen ylämäki muuttuu asfaltista kärrypoluksi ja…