Dapper Blog
Unity iOS Notifications with Big Image Attachments
Making delightful eye-catching notifications can improve engagement with your users and help your app standout. Unity APIs don’t provide rich notifications but it’s relatively easy to add images and other media attachments to your iOS notifications.
iOS supports both local and remote push notifications. We’ll be covering local notifications here. To add attachments for remote notifications you need to create a Notification Service Extension and
modify the content before its shown, typically passing an image url in the remote notification and then downloading and attaching at the time of presenting the notification.
For local notifications you can directly add attachments at the time of scheduling. However, for Unity games this means bridging from Unity into native code and managing the image resources across the Unity and native runtimes.
First we’ll need an image to attach to the notification. You can add the image into a
StreamingAssets folder but we’ll download the image on the fly to keep the app size down:
We download to the Application.persistentDataPath which is the internal sandbox data for the App’s
Home directory and is accessible from Unity and Native code.
You’ll need some Native code to schedule the notification. Objective-C / C is the easiest for Unity to link against. You’ll be passing the path of the image file just download to attach as well as other details for the notification from your Unity code. Create a C function for the scheduling the notification (it lives in a folder named Plugins/iOS):
Finally you need to bridge from Unity into your Native code: