Skip to content

Mattews92/InteractiveNotifications

Repository files navigation

InteractiveNotifications

The InteractiveNotifications project provides interactive Push Notifications and enables customisation of the notifications. Customisation requires two of the application extensions viz. Notification Service Extension and Notification Content Extension. Interactive local notifications are also added to the project.

How To Add Interactive Remote Notifications To Your Project

1. Download and use the InteractiveNotifications project frame.
     Or
2. Set up interactive notifications in your project.
In the YourProject.xcodeproj file, add new targets for the application extensions NotificationServiceExtension and NotificationContentExtension. Name the targets "NotificationService" and "NotificationContent" respectievely and activate them in the next popup.


Now in the project navigator replace the NotificationServiceExtension directory with the NotificationsService directory of InteractiveNotifications project. Similarly replace NotificationContentExtension with the NotificationContent directory in the InteractiveNotifications project.

Add the NotificationDelegate.swift, URLSessionExtension.swift and FileManagerExtension.swift files to the project and add NotificationService and NotificationContent in the target membership of all three files.

The NotificationService and NotificationContent app targets need seperate bundle URLs, mobile provisions and linked certificates to sign them.

Push Notification Payload

 {
   "aps":{
    "alert":"Custom Push",
    "badge":1,
    "sound":"default",
    "category":"CustomNotification",
    "mutable-content":"1"
    },
   "imageUrl":"your image url"
 }


This payload structure is to be followed in which the category value is to be unchanged. Application matches the category id to customise the notification. Customise the alert field with desired notification message and imageUrl with the desired image url. Use an optimal resolution image so that it can be downloaded in time. Also additional json nodes required by the application may be added to the payload.

How Interactive Remote Notifications Work

Interactive notifications adds the interactions when it registers for remote notifications. Customisation of the notifications are implemented with the aid of NotificationService and NotificationContent application extensions.

  • The NotificationDelegate class manages your remote notifications. Invoke this class from the func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool; method of AppDelegate as NotificationDelegate.sharedInstance.configureNotification() NotificationDelegate requests for push notifications and its UNUserNotificationCenterDelegate methods are invoked when a remote notification is received. Customise these delegates for actions when remote notification is received in the app
  • The URLSession Extension provides a custom method to download an Image from a URL
  • The FileManager Extension provides a custom method which saves and image from a url to the disk
  • The func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void); method in NotificationService class is invoked when a remote notification is received. An image is added to the notification in this method
  • The func didReceive(_ notification: UNNotification); method in the NotificationContent class is invoked when the notification detail is viewed in the tray. The detail view can be customised from the storyboard file. The notification category is specified in the info.plist file of NotificationContent target which can be employed to customise different notifications differently. Notification payload must use this category id

Interactive Local Notifications

Interactive local notifications are configured locally in the ViewController class. It is scheduled to fire after a delay employing a trigger. Interactive elements and attachments are configured for the notification. The UNUserNotificationCenterDelegate methods can be used to handle the notifications received by the app.

More frameworks

  • Slidermenu for Swift projects here
  • Boiler plate for swift projects here