Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

With the new iOS 10 you can attach a static or animated (gif) image, or even a video to push notifications. It will be displayed right in the notification when the user force-taps it. Link to apple video for rich messages support - https://developer.apple.com/videos/play/wwdc2016/708/

 

Create Notification Service Extension

  1. In XCode, Go to File -> New -> Target -> Notification Service Extension
  2. Create Notification Service Extension. Name your extension as NotificationService (You may choose a different name which will be referred to as Notification Service Target (name) in the subsequent sections).

     
  3. Click Activate to finish.
  4. At the end of this step, three new files will be created under NotificationService directory named:
    NotificationService.h
    NotificationService.m
    info.plist
  5. Open this up, and you’ll see a couple of delegate methods – one for receiving a notification request and one for handling the expiration of the service extension. We’ll be focussing on the first one, didReceiveRequestWithContentHandler.
  6. The code in this method should look like this:
     

     

    It may seem like a lot is happening here, but it’s straightforward really. Initially, we are exploring the notification’s payload for the dictionary named ‘data’ that contains the key ‘attachment-url’. If this key exists, we download the media at the URL specified in the key’s value. See, easy!

    The URLSession downloads the media to temporary storage and appends a .tmp file extension, which we need to remove so that the application can infer the file type and display it. So, to do this we need to move the file to the application’s local File Manager and that’s it – our media is ready to be attached to the notification content, and served to the user.

    This is all the code needed in your Xcode project to display rich notifications in your application.

    Now, you just need to make a few adjustments to the server that triggers Push Notifications to your application using our API.

  7. To send the rich pushes we can use Appoxee front end and pass the link as a key to the notification.

  8. Once notification is sent we will receive it like the example below 

That’s it! You can now send images, videos, audio, and GIFs in your iOS 10 Push Notifications! Simply change the URL to point to another media file, and see the results for yourself.

And of course; you could remove the media attachment and just send text.

 

 

  • No labels