Oracle Help Center | Oracle Push Cloud Service (Standalone) title

Media Attachments

This topic provides detailed instructions for integrating the Media Attachments feature as a part of push services.

How Media Attachments Work

"Media notification sample screenshot"

"Media long press sample screenshot"

Integrating the Media Attachments Framework into Your Mobile Application

Before You Begin:

Step 1: Create a target

[1.1]: Open the Xcode project (Example: HelloMedia is the name of the project shown in the following screenshot).

[1.2]: From the Xcode task bar, select File, then select New, then select Target.

"Creating A new target screenshot"

[1.3]: From the pop up, select Notification Service Extension as a template for your target.

"Select target template screenshot"

[1.4]: Enter a name for your target, set the other options as appropriate, and then click Finish to create the target. (In the following example, the user has typed MediaExtension for the target name.)

"Enter the name of target screenshot"

[1.5] After you have created the target, a slide-down alert is displayed. Select the Activate option.

Step 2: Add a framework

In addition to the PushIOManager framework, you must also add the PIOMediaAttachmentExtension framework to your project file.

[2.1]: Locate the Media Attachments framework and drag it into your project. Be sure to click “Copy items into destination group’s folder and choose the target created” in Xcode when adding files to your project (see screenshot below).

"Drag framework into project options screenshot"

Step 3: Implement code

[3.1]: Select your project from the left pane.

[3.2]: Select the folder named after your created target (in our previous example, 'MediaExtension' is the target name).

[3.3]: In the NotificationService.h file make the following changes:

1) Import the PIOMediaAttachmentExtension framework:

#import <PIOMediaAttachmentExtension/PIOMediaAttachmentServiceExtension.h>
        
import PIOMediaAttachmentExtension
        

2) Inherit PIOMediaAttachmentServiceExtension into NotificationService class:

Replace this:

      @interface NotificationService:UNNotificationServiceExtension
        

With this:

      @interface NotificationService :PIOMediaAttachmentServiceExtension
        

Replace this:

class NotificationService: UNNotificationServiceExtension
        

With this:

class NotificationService: PIOMediaAttachmentServiceExtension
        

[3.4]: In the NotificationService.m file make the following changes

1) Override the didReceiveNotificationRequest: withContentHandler method as : -

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler 
{
    [super didReceiveNotificationRequest:request withContentHandler:contentHandler];
}
        
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
    super.didReceive(request, withContentHandler: contentHandler)
}
        

2) Override the serviceExtensionTimeWillExpire method as : -

- (void)serviceExtensionTimeWillExpire 
  {
      [super serviceExtensionTimeWillExpire];
  }
        
override func serviceExtensionTimeWillExpire() {
    super.serviceExtensionTimeWillExpire()
}
        

Step 4: Run the application and the extension

[4.1]: Run the application on your device (assuming your device is connected to the system). Once the application is launched on the device, stop the application from Xcode.

"select app screenshot"

[4.2]: Select the target you had created (in our example, this was MediaExtension). Select the device you want to run it on (assuming your device is connected to the system).

"select media extension screenshot"

[4.3]: With the target selected, select build and choose your application from the dialog.

"Select application for target screenshot"

Step 5: Logging

To enable logging in PIOMediaAttachmentExtension:

// add the following code in the - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler function: 

[self enableLogging];
        
// add the following code in the override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) function: 

self.enableLogging()
        

To disable logging in PIOMediaAttachmentExtension:

// add the following code in the - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler  function : 

[self disableLogging];
        
// add the following code in the override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) function:

self.disableLogging()
        

Your application is now ready to receive notifications with media attachments.

If you encounter issues, please refer to the iOS FAQ topic.